1Which HTML tag is used to embed JavaScript code inside a webpage?
A.<js>
B.<script>
C.<javascript>
D.<code>
Correct Answer: <script>
Explanation:The <script> tag is the standard HTML element used to define client-side scripts, such as JavaScript.
Incorrect! Try again.
2Which attribute of the <script> tag is used to include an external JavaScript file?
A.href
B.link
C.src
D.rel
Correct Answer: src
Explanation:The 'src' attribute specifies the URL of an external script file.
Incorrect! Try again.
3Where is the correct place to insert a JavaScript in an HTML document?
A.The <head> section
B.The <body> section
C.Both the <head> section and the <body> section
D.The <footer> section
Correct Answer: Both the <head> section and the <body> section
Explanation:JavaScript can be placed in both the <head> and <body> sections of an HTML page, depending on when the script needs to load.
Incorrect! Try again.
4What is the correct file extension for an external JavaScript file?
A..java
B..js
C..script
D..html
Correct Answer: .js
Explanation:External JavaScript files are saved with the .js extension.
Incorrect! Try again.
5How do you write 'Hello World' in an alert box?
A.msg('Hello World');
B.msgBox('Hello World');
C.alertBox('Hello World');
D.alert('Hello World');
Correct Answer: alert('Hello World');
Explanation:The alert() function is used to display a popup box with a specified message.
Incorrect! Try again.
6Which keyword is used to declare a variable that cannot be reassigned?
A.var
B.let
C.const
D.static
Correct Answer: const
Explanation:The 'const' keyword defines a variable as a constant, meaning its value cannot be reassigned after initialization.
Incorrect! Try again.
7What is the scope of a variable declared with 'let' inside a block?
A.Global scope
B.Function scope
C.Block scope
D.Module scope
Correct Answer: Block scope
Explanation:Variables declared with 'let' are limited to the block, statement, or expression on which they are used.
Incorrect! Try again.
8Which operator is used to check both value and type equality?
A.==
B.=
C.===
D.!=
Correct Answer: ===
Explanation:The strict equality operator (===) checks if two values are equal in both value and data type.
Incorrect! Try again.
9What is the result of the expression: '5' + 3?
A.8
B.53
C.NaN
D.Error
Correct Answer: 53
Explanation:When a number is added to a string, JavaScript converts the number to a string and concatenates them.
Incorrect! Try again.
10Which function is used to get input from the user?
A.alert()
B.prompt()
C.confirm()
D.input()
Correct Answer: prompt()
Explanation:The prompt() method displays a dialog box that prompts the visitor for input.
Incorrect! Try again.
11What does the confirm() method return?
A.String
B.Integer
C.Boolean
D.Object
Correct Answer: Boolean
Explanation:The confirm() method returns true if the user clicks OK, and false if the user clicks Cancel.
Incorrect! Try again.
12How does a 'while' loop start?
A.while (i <= 10)
B.while i = 1 to 10
C.while (i <= 10; i++)
D.until (i <= 10)
Correct Answer: while (i <= 10)
Explanation:The syntax for a while loop is 'while (condition)'. It continues as long as the condition is true.
Incorrect! Try again.
13Which statement is used to stop a loop completely?
A.stop
B.return
C.break
D.continue
Correct Answer: break
Explanation:The 'break' statement terminates the current loop or switch statement and transfers control to the statement following the terminated statement.
Incorrect! Try again.
14What is the purpose of the 'continue' statement?
A.Stops the loop execution
B.Restarts the loop
C.Skips the current iteration
D.Exits the function
Correct Answer: Skips the current iteration
Explanation:The 'continue' statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration.
Incorrect! Try again.
15Which loop is guaranteed to execute at least once?
A.for
B.while
C.do...while
D.foreach
Correct Answer: do...while
Explanation:A do...while loop executes the code block once before checking if the condition is true, then it will repeat the loop as long as the condition is true.
Incorrect! Try again.
16How do you write an IF statement in JavaScript?
A.if i = 5
B.if i == 5 then
C.if (i == 5)
D.if i = 5 then
Correct Answer: if (i == 5)
Explanation:The correct syntax for an if statement requires the condition to be enclosed in parentheses: if (condition).
Incorrect! Try again.
17How do you write an IF statement for executing some code if 'i' is NOT equal to 5?
A.if (i <> 5)
B.if i =! 5 then
C.if (i != 5)
D.if i not 5
Correct Answer: if (i != 5)
Explanation:The operator != represents 'not equal to' in JavaScript.
Incorrect! Try again.
18Which symbol is used for single-line comments in JavaScript?
A.<!-- -->
B.//
C.//
D.**
Correct Answer: //
Explanation:Double slashes (//) are used for single-line comments in JavaScript.
Incorrect! Try again.
19What is the correct syntax for referring to an external script called 'app.js'?
A.<script name='app.js'>
B.<script href='app.js'>
C.<script src='app.js'>
D.<script file='app.js'>
Correct Answer: <script src='app.js'>
Explanation:The 'src' attribute is strictly used to link external JavaScript files.
Incorrect! Try again.
20How do you create a JavaScript object?
A.var obj = [];
B.var obj = {};
C.var obj = ();
D.var obj = <>;
Correct Answer: var obj = {};
Explanation:Curly braces {} are used to define an object literal in JavaScript.
Incorrect! Try again.
21Given: var person = {firstName:'John', lastName:'Doe'}; How do you access the lastName?
A.person.lastName
B.person[lastName]
C.person->lastName
D.person::lastName
Correct Answer: person.lastName
Explanation:Object properties are accessed using dot notation (object.property) or bracket notation with quotes (object['property']).
Incorrect! Try again.
22Which keyword is used to define a variable in JavaScript (ES5 legacy)?
A.dim
B.var
C.int
D.string
Correct Answer: var
Explanation:The 'var' keyword was the original way to declare variables in JavaScript before ES6 introduced 'let' and 'const'.
Incorrect! Try again.
23What is the correct way to write a JavaScript array?
34What is the correct way to check if a variable 'car' is undefined?
A.if (car === undefined)
B.if (car == null)
C.if (car is undefined)
D.if (typeof car == 'undefined')
Correct Answer: if (typeof car == 'undefined')
Explanation:Using typeof allows checking for undefined without throwing an error if the variable hasn't been declared.
Incorrect! Try again.
35Which of the following is NOT a valid JavaScript variable name?
A._myVar
B.$myVar
C.2myVar
D.myVar2
Correct Answer: 2myVar
Explanation:Variable names cannot start with a number.
Incorrect! Try again.
36What syntax is used to access a method 'start' of an object 'engine'?
A.engine['start']
B.engine.start()
C.call engine.start
D.engine->start()
Correct Answer: engine.start()
Explanation:Methods are accessed using dot notation followed by parentheses to invoke the function.
Incorrect! Try again.
37What happens if you redeclare a variable using 'let' in the same scope?
A.It overwrites the previous value
B.It causes a SyntaxError
C.It creates a new variable
D.Nothing happens
Correct Answer: It causes a SyntaxError
Explanation:Variables declared with 'let' (and 'const') cannot be redeclared in the same scope.
Incorrect! Try again.
38Which property is used to find the length of a string?
A.size
B.len
C.length
D.count
Correct Answer: length
Explanation:The .length property returns the number of characters in a string.
Incorrect! Try again.
39What is the output of Boolean(10 > 9)?
A.true
B.false
C.NaN
D.undefined
Correct Answer: true
Explanation:The expression 10 > 9 is true, so Boolean() returns true.
Incorrect! Try again.
40Which is the ternary operator?
A.?:
B.??
C.||
D.&&
Correct Answer: ?:
Explanation:The conditional (ternary) operator is the only JavaScript operator that takes three operands: condition ? exprIfTrue : exprIfFalse.
Incorrect! Try again.
41What keyword defines a switch case block?
A.option
B.case
C.when
D.if
Correct Answer: case
Explanation:The 'case' keyword marks a block of code to be executed in a switch statement if the match is found.
Incorrect! Try again.
42How do you delete a property from a JavaScript object?
A.remove object.property
B.delete object.property
C.object.property = null
D.clear object.property
Correct Answer: delete object.property
Explanation:The 'delete' operator removes a property from an object.
Incorrect! Try again.
43Which popup box returns null if the user clicks 'Cancel'?
A.alert
B.confirm
C.prompt
D.message
Correct Answer: prompt
Explanation:If the user clicks Cancel in a prompt box, the function returns null.
Incorrect! Try again.
44What is Hoisting in JavaScript?
A.Moving declarations to the top
B.Moving initializations to the top
C.Deleting unused variables
D.Looping efficiently
Correct Answer: Moving declarations to the top
Explanation:Hoisting is JavaScript's default behavior of moving declarations (specifically var and function declarations) to the top of the current scope.
Incorrect! Try again.
45Which of the following is a valid const declaration?
A.const PI;
B.const PI = 3.14;
C.const PI = 3.14; PI = 3.14159;
D.const 3.14 = PI;
Correct Answer: const PI = 3.14;
Explanation:Const variables must be assigned a value when they are declared.
Incorrect! Try again.
46What loop is best suited for iterating over the properties of an object?
A.for
B.while
C.for...in
D.do...while
Correct Answer: for...in
Explanation:The for...in loop iterates over the enumerable properties of an object.
Incorrect! Try again.
47Which symbol is used for the modulus (remainder) operator?
A./
B.%
C.*
D.&
Correct Answer: %
Explanation:The % operator returns the division remainder.
Incorrect! Try again.
48If x = 10 and y = '10', what is the result of x == y?
A.true
B.false
C.undefined
D.NaN
Correct Answer: true
Explanation:The == operator performs type coercion, so the number 10 is equal to the string '10'.
Incorrect! Try again.
49If x = 10 and y = '10', what is the result of x === y?
A.true
B.false
C.undefined
D.NaN
Correct Answer: false
Explanation:The === operator does not perform type coercion. A number is not strictly equal to a string.
Incorrect! Try again.
50Which global object do alert(), confirm(), and prompt() belong to?
A.document
B.console
C.window
D.html
Correct Answer: window
Explanation:These popup methods are part of the browser's Window object.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.