1Which of the following is the correct syntax for a single-line comment in JavaScript?
A.<!-- This is a comment -->
B./ This is a comment /
C.// This is a comment
D.# This is a comment
Correct Answer: // This is a comment
Explanation:In JavaScript, // is used for single-line comments, while /* ... */ is used for multi-line comments.
Incorrect! Try again.
2What is the result of the following expression: typeof null?
A."null"
B."undefined"
C."object"
D."number"
Correct Answer: "object"
Explanation:This is a historical bug in JavaScript. Although null is a primitive value, typeof null returns "object".
Incorrect! Try again.
3Which 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 declares a block-scoped variable that cannot be reassigned after its initial declaration.
Incorrect! Try again.
4What is the output of the code console.log(3 + "3");?
A.6
B."33"
C.33
D.TypeError
Correct Answer: "33"
Explanation:When the + operator is used with a number and a string, JavaScript converts the number to a string and performs concatenation.
Incorrect! Try again.
5Which operator is used to calculate the remainder of a division, represented mathematically as ?
A./
B.%
C.&
D.#
Correct Answer: %
Explanation:The modulus operator % returns the division remainder. For example, 10 % 3 returns 1.
Incorrect! Try again.
6What is the correct way to write an array in JavaScript?
A.var colors = "red", "green", "blue"
B.var colors = (1:"red", 2:"green", 3:"blue")
C.var colors = ["red", "green", "blue"]
D.var colors = {"red", "green", "blue"}
Correct Answer: var colors = ["red", "green", "blue"]
Explanation:Arrays in JavaScript are enclosed in square brackets [], with items separated by commas.
Incorrect! Try again.
7What is the output of 2 ** 3 in JavaScript?
A.5
B.6
C.8
D.9
Correct Answer: 8
Explanation:The ** operator is the exponentiation operator. It calculates the base to the exponent power, i.e., .
Incorrect! Try again.
8Which of the following creates a function using Arrow syntax?
A.function myFunction() {}
B.const myFunction = function() {}
C.const myFunction = () => {}
D.func myFunction = () -> {}
Correct Answer: const myFunction = () => {}
Explanation:Arrow functions introduced in ES6 use the => syntax. The correct format is (parameters) => { body }.
Incorrect! Try again.
9Which method is used to remove the last element from an array?
A.shift()
B.pop()
C.push()
D.remove()
Correct Answer: pop()
Explanation:The pop() method removes the last element from an array and returns that element. shift() removes the first element.
Incorrect! Try again.
10What applies to the scope of a variable declared with var?
A.It is always block-scoped.
B.It is function-scoped or globally scoped.
C.It is only available inside if statements.
D.It cannot be hoisted.
Correct Answer: It is function-scoped or globally scoped.
Explanation:Variables declared with var are function-scoped (if declared inside a function) or globally scoped. They ignore block scopes like if or for blocks.
Incorrect! Try again.
11How do you access the value of the property name in the object user?
A.user[name]
B.user.name
C.user(name)
D.user->name
Correct Answer: user.name
Explanation:Object properties are commonly accessed using dot notation (user.name). Bracket notation (user["name"]) requires quotes around the key.
Incorrect! Try again.
12Which comparison operator checks for both value and type (Strict Equality)?
A.=
B.==
C.===
D.!=
Correct Answer: ===
Explanation:The === operator checks strict equality, meaning both the value and the data type must match (e.g., 5 === "5" is false).
Incorrect! Try again.
13What is the result of Boolean("")?
A.true
B.false
C.undefined
D.null
Correct Answer: false
Explanation:In JavaScript, an empty string "" is a falsy value. Therefore, converting it to a Boolean results in false.
Incorrect! Try again.
14Which method attaches an event handler to an HTML element?
A.attachEvent()
B.on()
C.addEventListener()
D.listen()
Correct Answer: addEventListener()
Explanation:The addEventListener() method is the standard way to register an event handler for a specific event type on an element.
Incorrect! Try again.
15How do you write an if statement that executes code if i is NOT equal to 5?
A.if i <> 5
B.if (i != 5)
C.if (i =! 5)
D.if i != 5 then
Correct Answer: if (i != 5)
Explanation:The inequality operator is !=. The condition must be enclosed in parentheses.
Incorrect! Try again.
16What is the correct syntax for referring to an external script called app.js?
A.<script href="app.js">
B.<script src="app.js">
C.<script name="app.js">
D.<link src="app.js">
Correct Answer: <script src="app.js">
Explanation:The <script> tag uses the src attribute to link to external JavaScript files.
Incorrect! Try again.
17Which of the following is NOT a JavaScript data type?
A.Number
B.Boolean
C.Float
D.Undefined
Correct Answer: Float
Explanation:JavaScript does not have a specific Float or Integer type; all numbers are of the type Number (IEEE 754 doubles).
Incorrect! Try again.
18What keyword allows you to return a value from a function?
A.send
B.return
C.output
D.break
Correct Answer: return
Explanation:The return statement ends function execution and specifies a value to be returned to the function caller.
Incorrect! Try again.
19In the DOM, which object represents the browser window?
A.document
B.body
C.window
D.browser
Correct Answer: window
Explanation:The window object represents the browser's window and is the global object in client-side JavaScript.
Incorrect! Try again.
20How does a while loop differ from a do...while loop?
A.A while loop runs at least once.
B.A do...while loop checks the condition before the block.
C.A do...while loop runs the block at least once before checking the condition.
D.There is no difference.
Correct Answer: A do...while loop runs the block at least once before checking the condition.
Explanation:In a do...while loop, the code block is executed once before the condition is evaluated. A while loop evaluates the condition first.
Incorrect! Try again.
21What is the purpose of the this keyword?
A.It refers to the current function.
B.It refers to the object from which the function was called.
C.It refers to the global variable scope.
D.It refers to the previous variable used.
Correct Answer: It refers to the object from which the function was called.
Explanation:this refers to the execution context (the object) that 'owns' the function call. In the global scope, it refers to the window object.
Incorrect! Try again.
22Which statement correctly creates a constant array?
Explanation:Use the const keyword. Note that while the variable cars cannot be reassigned, the elements inside the array can be modified.
Incorrect! Try again.
23What logic does the operator || represent?
A.Logical AND
B.Logical OR
C.Logical NOT
D.Bitwise OR
Correct Answer: Logical OR
Explanation:The || operator represents Logical OR. It returns true if at least one of the operands is true.
Incorrect! Try again.
24How do you check the length of an array named tasks?
A.tasks.length
B.tasks.size()
C.tasks.count
D.tasks.length()
Correct Answer: tasks.length
Explanation:In JavaScript, arrays have a length property (not a method) that holds the number of elements.
Incorrect! Try again.
25Which method is used to convert a JSON string into a JavaScript object?
A.JSON.stringify()
B.JSON.parse()
C.JSON.toObject()
D.JSON.convert()
Correct Answer: JSON.parse()
Explanation:JSON.parse() takes a JSON string and transforms it into a JavaScript object. JSON.stringify() does the reverse.
Incorrect! Try again.
26What is the output of console.log(10 == "10")?
A.true
B.false
C.undefined
D.NaN
Correct Answer: true
Explanation:The loose equality operator == performs type coercion, converting the string "10" to a number before comparing. Thus, the result is true.
Incorrect! Try again.
27Which event occurs when a user clicks on an HTML element?
A.onchange
B.onmouseover
C.onclick
D.onmouseclick
Correct Answer: onclick
Explanation:The onclick event is triggered when the user clicks on an element.
Incorrect! Try again.
28What is the correct way to select an HTML element by its ID?
A.document.selectId("myId")
B.document.getElementById("myId")
C.document.querySelector("myId")
D.window.getId("myId")
Correct Answer: document.getElementById("myId")
Explanation:getElementById is the standard DOM method to retrieve an element by its unique id attribute.
Incorrect! Try again.
29Which statement stops the execution of a loop but allows the loop to continue with the next iteration?
A.stop
B.break
C.exit
D.continue
Correct Answer: continue
Explanation:The continue statement skips the current iteration of the loop and proceeds to the next iteration. break exits the loop entirely.
Incorrect! Try again.
30Which variable declaration is hoisted to the top of its scope and initialized with undefined?
A.let
B.const
C.var
D.func
Correct Answer: var
Explanation:var declarations are hoisted and initialized with undefined. let and const are hoisted but remain in the 'Temporal Dead Zone' until declared.
Incorrect! Try again.
31What does isNaN() function check?
A.If a value is null
B.If a value is a number
C.If a value is Not-a-Number
D.If a value is infinite
Correct Answer: If a value is Not-a-Number
Explanation:isNaN() determines whether a value is NaN (Not-a-Number) or can be converted to a number.
Incorrect! Try again.
32What syntax allows you to unpack values from arrays into distinct variables?
A.Hoisting
B.Destructuring
C.Spread operator
D.Literal Syntax
Correct Answer: Destructuring
Explanation:Destructuring assignment is a syntax that makes it possible to unpack values from arrays (or properties from objects) into distinct variables.
Incorrect! Try again.
33What is the result of "Hello".charAt(0)?
A."e"
B."H"
C."Hello"
D.0
Correct Answer: "H"
Explanation:Strings are zero-indexed. charAt(0) returns the character at the first position, which is "H".
Incorrect! Try again.
34Which operator is used for the logical NOT operation?
A.!
B.|
C.&
D.~
Correct Answer: !
Explanation:The ! operator inverts the boolean value of an operand (e.g., !true becomes false).
Incorrect! Try again.
35What is the correct syntax for a switch statement?
A.switch (expression) { case x: code block; break; }
Explanation:A switch statement evaluates an expression and matches the value to a case clause.
Incorrect! Try again.
36Which array method creates a new array by performing a function on each array element?
A.forEach()
B.map()
C.filter()
D.every()
Correct Answer: map()
Explanation:map() iterates over the array, calls the provided function on each element, and returns a new array containing the results.
Incorrect! Try again.
37What is the value of x after: let x = 5; x += 3;?
A.5
B.3
C.8
D.53
Correct Answer: 8
Explanation:The assignment operator += adds the right operand to the left operand. .
Incorrect! Try again.
38Which of the following is true about arrow functions and the this keyword?
A.Arrow functions have their own this binding.
B.Arrow functions inherit this from the parent scope.
C.Arrow functions cannot use this.
D.this in arrow functions always refers to the window.
Correct Answer: Arrow functions inherit this from the parent scope.
Explanation:Arrow functions do not bind their own this. They lexically bind this, meaning they inherit it from the surrounding code.
Incorrect! Try again.
39To prevent a form from submitting when a button is clicked, which method is used on the event object?
A.event.stop()
B.event.halt()
C.event.preventDefault()
D.event.stopPropagation()
Correct Answer: event.preventDefault()
Explanation:event.preventDefault() stops the default action of an element from happening (e.g., preventing a form submission or a link follow).
Incorrect! Try again.
40Which popup box displays a message and returns true (OK) or false (Cancel)?
A.alert()
B.prompt()
C.confirm()
D.message()
Correct Answer: confirm()
Explanation:confirm() displays a dialog box with a specified message, along with an OK and a Cancel button.
Incorrect! Try again.
41If var a = [1, 2, 3];, what is a[3]?
A.3
B.2
C.undefined
D.null
Correct Answer: undefined
Explanation:Arrays are 0-indexed. Indices are 0, 1, 2. Accessing index 3 (which does not exist) returns undefined.
Incorrect! Try again.
42Which of the following is a Template Literal?
A."Hello World"
B.'Hello World'
C.Hello World
D.(Hello World)
Correct Answer: Hello World
Explanation:Template literals are enclosed by backticks (`) and allow for embedded expressions and multi-line strings.
Incorrect! Try again.
43What does the push() method return?
A.The new array
B.The new length of the array
C.The element that was added
D.undefined
Correct Answer: The new length of the array
Explanation:push() adds elements to the end of an array and returns the new length of the array.
Incorrect! Try again.
44What is the global scope in a browser environment?
A.The HTML file
B.The document object
C.The window object
D.The console object
Correct Answer: The window object
Explanation:In web browsers, the window object acts as the global scope. Global variables become properties of window.
Incorrect! Try again.
45Which method is used to write HTML expressions or JavaScript code to a document?
A.window.print()
B.document.write()
C.console.log()
D.innerHTML
Correct Answer: document.write()
Explanation:document.write() writes a string of text to a document stream opened by document.open().
Incorrect! Try again.
46What happens if you define a variable without var, let, or const in strict mode?
A.It becomes a global variable.
B.It becomes a local variable.
C.It throws a ReferenceError.
D.It creates a constant.
Correct Answer: It throws a ReferenceError.
Explanation:Strict mode ('use strict';) prevents the accidental creation of global variables. Undeclared variables cause an error.
Incorrect! Try again.
47Which logical operator has the highest precedence?
A.|| (OR)
B.&& (AND)
C.! (NOT)
D.They have equal precedence
Correct Answer: ! (NOT)
Explanation:The Logical NOT (!) operator has higher precedence than AND (&&) and OR (||).
Incorrect! Try again.
48How do you define a default parameter in a function?
A.function myFunc(x = 10) { }
B.function myFunc(x : 10) { }
C.function myFunc(x default 10) { }
D.function myFunc(x) { x = 10; }
Correct Answer: function myFunc(x = 10) { }
Explanation:ES6 introduced default parameters directly in the function definition: function name(param = value).
Incorrect! Try again.
49What property replaces the content of an HTML element, parsing the new content as HTML?
A.innerText
B.textContent
C.innerHTML
D.value
Correct Answer: innerHTML
Explanation:innerHTML gets or sets the HTML markup contained within an element. innerText treats the content as raw text.
Incorrect! Try again.
50Which of these is a valid ternary operator expression?
A.condition ? expr1 : expr2
B.condition : expr1 ? expr2
C.condition ? expr1 ? expr2
D.condition ?? expr1 : expr2
Correct Answer: condition ? expr1 : expr2
Explanation:The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by ?, then an expression to execute if true, followed by :, and an expression if false.