MCQs Of Day 1
Introduction to JavaScript
1. What is JavaScript primarily used for in web development?
o A) Server-side scripting
o B) Styling webpages
o C) Client-side scripting and adding interactivity
o D) Database management
2. Which of the following is the correct syntax to link an external JavaScript file?
o A) <script href="file.js"></script>
o B) <script link="file.js"></script>
o C) <script src="file.js"></script>
o D) <script file="file.js"></script>
3. Which company developed JavaScript?
o A) Microsoft
o B) Google
o C) Oracle
o D) Netscape
4. In what year was JavaScript created?
o A) 1991
o B) 1995
o C) 1999
o D) 2002
5. JavaScript is a ____ typed language.
o A) Statically
o B) Dynamically
o C) Strongly
o D) Weakly
6. Which keyword is used to declare a variable in JavaScript?
o A) int
o B) var
o C) define
o D) set
7. Which of the following correctly declares a constant variable?
o A) const myConstant = 10;
o B) constant myConstant = 10;
o C) let myConstant = 10;
o D) var myConstant = 10;
8. What will typeof "hello" return?
o A) number
o B) string
o C) boolean
o D) object
9. Which data type is NOT available in JavaScript?
o A) String
o B) Number
o C) Tuple
o D) Object
10. What will the following code output? console.log(typeof null);
o A) object
o B) null
o C) undefined
o D) number
11. What is the output of 5 + "5" in JavaScript?
o A) 10
o B) 55
o C) NaN
o D) 5
12. Which operator is used to assign a value to a variable?
o A) =
o B) ==
o C) ===
o D) !=
13. What will 10 % 3 output in JavaScript?
o A) 1
o B) 3
o C) 0
o D) 10
14. What does the ++ operator do to a variable?
o A) Multiplies by 2
o B) Divides by 2
o C) Increases by 1
o D) Decreases by 1
15. Which of the following is the strict equality operator?
o A) =
o B) ==
o C) ===
o D) !=
16. Which of the following is NOT a valid loop in JavaScript?
o A) for
o B) while
o C) do-while
o D) repeat-until
17. What will for (let i = 0; i < 3; i++) console.log(i); output?
o A) 0 1 2 3
o B) 0 1 2
o C) 1 2 3
o D) 1 2
18. How can you break out of a loop in JavaScript?
o A) exit
o B) return
o C) stop
o D) break
19. What will the following code print?
let x = 10;
if (x > 5) {
console.log("Greater");
} else {
console.log("Smaller");
}
o A) Greater
o B) Smaller
o C) Undefined
o D) null
20. Which statement is used to skip an iteration in a loop?
o A) skip
o B) continue
o C) pass
o D) stop
21. Which of the following correctly defines a function in JavaScript?
o A) def myFunction() {}
o B) function myFunction() {}
o C) myFunction = function {}
o D) define myFunction() {}
22. Which keyword is used to return a value from a function?
o A) return
o B) output
o C) yield
o D) print
23. What will the following code output?
function add(a, b) {
return a + b;
}
console.log(add(3, 4));
o A) 7
o B) 34
o C) undefined
o D) null
24. What will console.log(add); output if function add() {} is defined?
o A) undefined
o B) [object Function]
o C) function add() {}
o D) add()
25. Can functions in JavaScript be anonymous?
o A) Yes
o B) No
26. What does DOM stand for in JavaScript?
o A) Document Oriented Model
o B) Data Object Model
o C) Document Object Model
o D) Data Oriented Model
27. Which method is used to select an element by its ID in JavaScript?
o A) getElementByName()
o B) getElementById()
o C) getElementsByTagName()
o D) querySelector()
28. How can you change the text content of an HTML element with JavaScript?
o A) element.innerHTML
o B) element.textContent
o C) element.value
o D) element.content
29. What will document.querySelector("p"); return?
o A) All <p> elements
o B) The first <p> element
o C) Undefined
o D) An array of all <p> elements
30. Which method adds a new child element to a selected element?
o A) append()
o B) addChild()
o C) appendChild()
o D) addElement()
31. What does removeChild() do in JavaScript?
o A) Removes a child element
o B) Removes all child elements
o C) Removes an attribute
o D) Removes the parent element
32. How would you change the background color of an element with id="box"?
o A) document.getElementById("box").style.backgroundColor = "blue";
o B) document.getElementById("box").backgroundColor = "blue";
o C) document.querySelector("#box").style.color = "blue";
o D) document.querySelector("#box").style.background = blue;
33. Which method is used to find all elements of a class name?
o A) getElementsByClass()
o B) getElementsByClassName()
o C) querySelector()
o D) getElementsById()
34. What does document.createElement("div") do?
o A) Creates a new HTML document
o B) Creates a new <div> element
o C) Selects a <div> element
o D) Replaces an existing <div> element
35. Which of the following correctly appends an element to the document body?
o A) document.appendChild(element);
o B) document.body.appendChild(element);
o C) body.appendChild(element);
o D) appendChild(body, element);
36. Which event occurs when a user clicks on an HTML element?
o A) onmouseover
o B) onclick
o C) onload
o D) onchange
37. How do you add an event listener to a button with id="btn"?
o A) document.getElement("btn").click = function(){}
o B) document.querySelector("#btn").click(function(){})
o C) document.getElementById("btn").addEventListener("click", function(){});
o D) addEventListener("click", function(){}, "btn");
38. Which event is triggered when a user presses a key?
o A) keydown
o B) keypress
o C) keyup
o D) All of the above
39. Which event is used when an HTML form is submitted?
o A) onsubmit
o B) onchange
o C) oninput
o D) onsave
40. How can you prevent the default action in an event?
o A) event.prevent()
o B) event.preventAction()
o C) event.preventDefault()
o D) event.stop()
Error Handling
41. Which of the following keywords is used to handle exceptions in JavaScript?
o A) catch
o B) try
o C) throw
o D) All of the above
42. Which statement is used to throw an error manually?
o A) throw
o B) try
o C) catch
o D) manual
43. What will happen if an error occurs in the try block?
o A) The code execution stops
o B) The catch block will handle the error
o C) The code skips to the end
o D) None of the above
44. Which keyword is used to execute code regardless of whether an error occurs?
o A) always
o B) finally
o C) after
o D) lastly
45. What is the output of the following code?
try {
throw "Error!";
} catch (e) {
console.log(e);
}
o A) undefined
o B) Error!
o C) null
o D) Exception
46. Which keyword was introduced in ES6 to declare block-scoped variables?
o A) var
o B) const
o C) let
o D) Both let and const
47. What does the => symbol signify in JavaScript?
o A) Equality
o B) Function keyword
o C) Arrow function
o D) Scope resolution
48. What is the default parameter in functions used for?
o A) To pass mandatory parameters
o B) To initialize arguments if no value is passed
o C) To handle exceptions
o D) To specify variable types
49. Which of the following is NOT a feature of arrow functions?
o A) They do not have their own this
o B) They are shorter syntax
o C) They are block-scoped
o D) They are compatible with arguments object
50. How would you write a template literal in JavaScript?
o A) "Hello ${name}"
o B) "Hello" + name + ""
o C) `Hello ${name}`
o D) 'Hello {name}'
51. Which method adds one or more elements to the end of an array and returns the new length?
o A) push()
o B) pop()
o C) shift()
o D) unshift()
52. What does the pop() method do in an array?
o A) Removes the first element
o B) Adds a new element at the beginning
o C) Removes the last element
o D) Sorts the array
53. How can you find the number of elements in an array arr?
o A) arr.size
o B) arr.length
o C) arr.count()
o D) arr.length()
54. Which method creates a new array with all elements that pass the test implemented by the provided function?
o A) filter()
o B) map()
o C) reduce()
o D) forEach()
55.What will the following code output?
let fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[1]);
o A) Apple
o B) Banana
o C) Cherry
o D) undefined
56. Which method combines two or more arrays?
o A) concat()
o B) merge()
o C) join()
o D) combine()
57. How do you remove the first element from an array?
o A) arr.pop()
o B) arr.shift()
o C) arr.unshift()
o D) arr.splice(0, 1)
58. What does the slice() method do?
o A) Removes elements from the array
o B) Returns a shallow copy of a portion of an array
o C) Sorts the array
o D) Reverses the array
59. Which method executes a provided function once for each array element?
o A) map()
o B) filter()
o C) forEach()
o D) reduce()
60. How can you check if a variable arr is an array?
o A) typeof arr === "array"
o B) arr instanceof Array
o C) Array.isArray(arr)
o D) Both B and C
61. How do you create an object in JavaScript?
o A) let obj = {};
o B) let obj = [];
o C) let obj = () => {};
o D) let obj = new Object[];
62. How can you access the value of the property name in an object person?
o A) person.name
o B) person[name]
o C) person->name
o D) Both A and B
63. Which method is used to add a new property to an existing object?
o A) addProperty()
o B) setProperty()
o C) Direct assignment (e.g., obj.newProp = value)
o D) Object.assign()
64. What will delete obj.property do?
o A) Remove the property from the object
o B) Set the property value to null
o C) Set the property value to undefined
o D) Throw an error
65. How can you iterate over all properties in an object obj?
o A) for (let key in obj) { ... }
o B) for (let key of obj) { ... }
o C) obj.forEach((key) => { ... })
o D) while (obj.hasNext()) { ... }
66. Which of the following is a correct way to define a method inside an object?
o A)
let obj = {
greet: function() {
console.log("Hello");
}
};
o B)
let obj = {
greet() {
console.log("Hello");
}
};
o C) Both A and B
o D) Neither A nor B
67. What will the following code output?
let car = { make: "Toyota", model: "Camry" };
console.log(car["make"]);
o A) car.make
o B) "make"
o C) "Toyota"
o D) undefined
68. Which function can be used to convert an object to a JSON string?
o A) JSON.parse()
o B) JSON.stringify()
o C) JSON.convert()
o D) JSON.toString()
69. How do you define a constructor function for an object Person?
o A)
function Person(name) {
this.name = name;
}
o B)
let Person = {
name: ""
};
o C)
class Person {
constructor(name) {
this.name = name;
}
}
o D) Both A and C
70.What is the output of the following code?
let obj = { a: 1, b: 2 };
for (let key in obj) {
console.log(key);
}
o A) 1 2
o B) a b
o C) undefined
o D) ["a", "b"]
71. Which method returns the length of a string?
o A) length()
o B) size()
o C) count()
o D) length
72. How do you convert a string to uppercase in JavaScript?
o A) str.toUpper()
o B) str.toUpperCase()
o C) str.upper()
o D) str.changeCase("upper")
73. Which method is used to find the index of a substring within a string?
o A) search()
o B) indexOf()
o C) find()
o D) locate()
74. What will "Hello World".substring(0, 5) return?
o A) "Hello"
o B) "World"
o C) "Hello World"
o D) "ello "
75. Which method replaces a specified value with another value in a string?
o A) replace()
o B) swap()
o C) change()
o D) modify()
76. How do you extract the last character from a string str?
o A) str.slice(-1)
o B) str.substring(str.length - 1)
o C) str.charAt(str.length - 1)
o D) All of the above
77.What is the result of "JavaScript".includes("Script")?
o A) true
o B) false
o C) undefined
o D) Throws an error
78. Which method splits a string into an array of substrings?
o A) split()
o B) divide()
o C) segment()
o D) partition()
79. How can you trim whitespace from both ends of a string str?
o A) str.trim()
o B) str.removeSpaces()
o C) str.trimSpaces()
o D) str.strip()
80. What does the charAt() method do?
o A) Returns the character at a specified index
o B) Returns the ASCII value of a character
o C) Replaces a character at a specified index
o D) Converts a character to uppercase
81. How do you create a new Date object representing the current date and time?
o A) new Date()
o B) Date.now()
o C) new DateTime()
o D) Date.create()
82. Which method returns the number of milliseconds since January 1, 1970?
o A) Date.now()
o B) Date.getTime()
o C) Date.current()
o D) Date.milliseconds()
83. How can you get the current year from a Date object d?
o A) d.getFullYear()
o B) d.getYear()
o C) d.year
o D) d.currentYear()
o A) 2
o B) 3
o C) 4
o D) 5
85. Which method sets the month of a Date object?
o A) setMonth()
o B) updateMonth()
o C) changeMonth()
o D) modifyMonth()
86. How do you convert a Date object to a string?
o A) d.toString()
o B) d.stringify()
o C) d.convertToString()
o D) d.asString()
87. What is the output of new Date(0)?
o A) The current date and time
o B) January 1, 1970, 00:00:00 UTC
o C) Invalid Date
o D) null
88. Which method retrieves the hours from a Date object d?
o A) d.getHours()
o B) d.getTime()
o C) d.getUTCHours()
o D) d.getHour()
89. How can you add 5 days to the current date?
o A)
let d = new Date();
d.setDate(d.getDate() + 5);
o B)
let d = new Date();
d.addDays(5);
o C)
let d = new Date();
d.date += 5;
o D)
let d = new Date();
d.setDay(d.getDay() + 5);
90. What does the toISOString() method do?
o A) Converts the date to a string using the local time zone
o B) Converts the date to a string in ISO 8601 format
o C) Returns the date as a UNIX timestamp
o D) Formats the date as "MM/DD/YYYY"
91. What does JSON stand for?
o A) JavaScript Object Notation
o B) Java Source Object Notation
o C) JavaScript Ordered Namespace
o D) Java Simple Object Notation
92. Which method parses a JSON string into a JavaScript object?
o A) JSON.parse()
o B) JSON.stringify()
o C) JSON.convert()
o D) JSON.decode()
93. Which method converts a JavaScript object into a JSON string?
o A) JSON.parse()
o B) JSON.stringify()
o C) JSON.encode()
o D) JSON.toString()
94. What is the correct JSON format for an object with a name and age?
o A) {name: "John", age: 30}
o B) {"name": "John", "age": 30}
o C) {"name" => "John", "age" => 30}
o D) {name => "John", age => 30}
95. Can JSON contain functions as values?
o A) Yes
o B) No
96. Which of the following is a valid JSON array?
o A) ["apple", "banana", "cherry"]
o B) {1, 2, 3}
o C) ("apple", "banana", "cherry")
o D) "apple", "banana", "cherry"
97. **How do you access the age property from the following JSON string?
'{"name": "Alice", "age": 25}'
**
o A) obj.age
o B) obj["age"]
o C) Both A and B
o D) Neither A nor B
98. What will JSON.stringify({a:1, b:2}) return?
o A) "{a:1, b:2}"
o B) '{"a":1, "b":2}'
o C) ["a",1,"b",2]
o D) "{\"a\":1, \"b\":2}"
99. Which of the following is true about JSON?
o A) JSON is a subset of JavaScript
o B) JSON is language-independent
o C) JSON requires property names to be double-quoted
o D) All of the above
101. Which keyword is used to declare a block-scoped variable that cannot be reassigned?
o A) var
o B) let
o C) const
o D) static
103. Which feature allows for destructuring objects and arrays?
o A) Spread Operator
o B) Rest Operator
o C) Destructuring Assignment
o D) Template Literals
104. What does the spread operator (...) do in JavaScript?
o A) Combines arrays or objects
o B) Creates a copy of an array or object
o C) Both A and B
o D) Neither A nor B
105. Which of the following is a valid arrow function syntax?
o A) function() => {}
o B) () => {}
o C) => () {}
o D) {} => ()
106. What is a default parameter in ES6?
o A) A parameter that is optional
o B) A parameter with a default value if none is provided
o C) A parameter that must be provided
o D) A deprecated feature
107. How do you import a default export from a module in ES6?
o A) import { default } from 'module';
o B) import default from 'module';
o C) import anyName from 'module';
o D) require('module').default;
108. Which method can be used to combine multiple promises into a single promise?
o A) Promise.all()
o B) Promise.race()
o C) Promise.combine()
o D) Promise.merge()
109. What is a template literal in ES6?
o A) A string defined with single quotes
o B) A string defined with double quotes
o C) A string defined with backticks allowing embedded expressions
o D) A new data type
110. Which feature allows you to write asynchronous code that looks synchronous?
o A) Callbacks
o B) Promises
o C) Async/Await
o D) Event Loop
111. What is the purpose of the typeof operator?
o A) To check if a variable is defined
o B) To determine the type of a variable
o C) To convert a variable to a string
o D) To clone a variable
112. Which symbol is used for single-line comments in JavaScript?
o A) /* */
o B) //
o C) <!-- -->
o D) #
113. What will console.log(0.1 + 0.2 === 0.3) output?
o A) true
o B) false
o C) undefined
o D) Throws an error
114. Which statement is used to exit a function and return a value?
o A) break
o B) continue
o C) return
o D) exit
115. What is the result of typeof NaN?
o A) number
o B) NaN
o C) undefined
o D) object
116. Which method can be used to clone an object?
o A) Object.clone()
o B) Object.assign({}, obj)
o C) JSON.parse(JSON.stringify(obj))
o D) Both B and C
117. What does the void operator do in JavaScript?
o A) Returns undefined
o B) Deletes a property
o C) Converts a value to boolean
o D) No such operator exists
118. Which of the following is a self-invoking function?
o A)
function() { console.log("Hi"); }
- B)
```javascript
(function() { console.log("Hi"); })();
```
- C)
```javascript
() => { console.log("Hi"); }
```
- D)
```javascript
function greet() { console.log("Hi"); }
greet();
```
- **Answer:** B
**Explanation:** A self-invoking function is immediately invoked after its definition, as shown in option B.
120. Which statement is used to declare a block scope in ES6?
o A) var
o B) let
o C) const
o D) Both B and C
Advanced Topics
121. What is the purpose of the bind() method in JavaScript?
o A) To create a new function with a bound this value
o B) To attach an event listener
o C) To merge two objects
o D) To iterate over array elements
122. Which statement is true about JavaScript closures?
o A) They allow functions to access variables from an outer function scope
o B) They are a way to bind this keyword
o C) They are similar to classes in other languages
o D) They are deprecated in ES6
123. What does the new keyword do in JavaScript?
o A) Creates a new object
o B) Calls a function
o C) Returns a copy of an object
o D) Deletes an object
124. Which of the following is NOT a primitive data type in JavaScript?
o A) String
o B) Number
o C) Boolean
o D) Object
125. What is the purpose of the finally block in a try...catch statement?
o A) To handle errors
o B) To execute code after try and catch regardless of the outcome
o C) To retry the try block
o D) To define custom error messages
126. How do you prevent a form from submitting and refreshing the page?
o A) event.preventDefault();
o B) return false;
o C) Both A and B
o D) Neither A nor B
127. Which feature allows JavaScript to perform tasks asynchronously?
o A) Callbacks
o B) Promises
o C) Async/Await
o D) All of the above
128. What is the result of '5' - 3 in JavaScript?
o A) '53'
o B) 2
o C) NaN
o D) '2'
129. Which statement correctly checks if variable x is exactly equal to 10?
o A) x == 10
o B) x === 10
o C) x = 10
o D) x != 10
130. What does the async keyword do when placed before a function?
o A) Makes the function execute faster
o B) Allows the use of await inside the function
o C) Converts the function to a promise
o D) Both B and C
Prototypal Inheritance
131. What is prototypal inheritance in JavaScript?
o A) A way to create classes
o B) A mechanism where objects inherit properties from other objects
o C) A type of loop
o D) A method for error handling
132. How do you set the prototype of an object child to parent?
o A) child.prototype = parent;
o B) Object.setPrototypeOf(child, parent);
o C) child.__proto__ = parent;
o D) Both B and C
134. Which method returns the prototype of an object?
o A) Object.getPrototype()
o B) Object.getPrototypeOf()
o C) Object.prototype()
o D) getPrototypeOf()
135. Can you modify the prototype of built-in objects like Array in JavaScript?
o A) Yes, but it's not recommended
o B) No, it's impossible
o C) Yes, and it's recommended
o D) Only in strict mode
136. What is the constructor property used for?
o A) To create new instances
o B) To reference the function that created the instance's prototype
o C) To initialize object properties
o D) To delete object properties
137. Which keyword is used to inherit from another class in ES6?
o A) inherit
o B) extends
o C) implements
o D) super
138. What does the super keyword do in a subclass constructor?
o A) Calls the parent class constructor
o B) Binds this to the parent class
o C) Creates a new instance of the parent class
o D) All of the above
139. What is the default prototype of an object created with {}?
o A) Object.prototype
o B) null
o C) Function.prototype
o D) Array.prototype
140. How can you check if an object obj has a property prop as its own property (not inherited)?
o A) obj.hasOwnProperty(prop)
o B) prop in obj
o C) Object.hasOwn(obj, prop)
o D) Both A and C
Asynchronous JavaScript
141. What does the fetch() function do?
o A) Fetches elements from the DOM
o B) Makes HTTP requests to retrieve resources
o C) Fetches data from local storage
o D) None of the above
142. How do you handle errors in a Promise chain?
o A) Using .then()
o B) Using .catch()
o C) Using try...catch
o D) Using finally
144. Which keyword is used to pause the execution of an async function until a Promise is resolved?
o A) await
o B) pause
o C) sleep
o D) break
145. What does the Promise.all() method do?
o A) Resolves as soon as one of the promises resolves
o B) Rejects as soon as one of the promises rejects
o C) Waits for all promises to resolve or any to reject
o D) None of the above
146. Which method starts executing a Promise and returns a promise that resolves when the first promise resolves or rejects when the first promise rejects?
o A) Promise.all()
o B) Promise.race()
o C) Promise.any()
o D) Promise.resolve()
148. Which of the following is true about JavaScript's event loop?
o A) It allows JavaScript to perform non-blocking operations
o B) It manages the execution of multiple threads
o C) It is responsible for garbage collection
o D) It only handles UI rendering
149. What is the purpose of the setTimeout() function?
o A) To execute a function after a specified delay
o B) To repeatedly execute a function at specified intervals
o C) To pause execution indefinitely
o D) To stop a function from executing
150. Which function can be used to repeatedly execute a function at fixed time intervals?
o A) setTimeout()
o B) setInterval()
o C) requestAnimationFrame()
o D) setImmediate()
Modules and Imports
151. How do you export a function named myFunction in ES6 modules?
o A) export myFunction;
o B) export { myFunction };
o C) module.exports = myFunction;
o D) export default myFunction;
152. How do you import all exported members from a module named utils.js?
o A) import * as utils from './utils.js';
o B) import utils from './utils.js';
o C) import { utils } from './utils.js';
o D) import all from './utils.js';
153. What is the default file extension for ES6 modules?
o A) .js
o B) .mjs
o C) .es6
o D) Both A and B
154. Which statement allows you to export multiple functions from a module?
o A) export default function1, function2;
o B) export { function1, function2 };
o C) module.exports = { function1, function2 };
o D) Both B and C
155. How do you import a default export from a module?
o A) import { default as func } from './module.js';
o B) import func from './module.js';
o C) import default func from './module.js';
o D) import { func } from './module.js';
156. Which of the following is true about ES6 modules?
o A) They are loaded synchronously by default
o B) They are loaded asynchronously by default
o C) They cannot export multiple values
o D) They are not supported in browsers
157. What is the purpose of the export default statement?
o A) To export multiple values
o B) To export a single default value from a module
o C) To export only functions
o D) To export only classes
158. Can ES6 modules import other modules?
o A) Yes
o B) No
159. Which of the following is a correct way to export a constant PI?
o A) export const PI = 3.14;
o B) const PI = 3.14; export PI;
o C) export { PI };
o D) All of the above (with appropriate definitions)
160. What will happen if you try to import a non-existent export from a module?
o A) It will return undefined
o B) It will throw a compile-time error
o C) It will throw a runtime error
o D) It will silently fail
Advanced Functions and Concepts
161. What is the difference between call() and apply() methods?
o A) call() passes arguments as a list, apply() passes them as an array
o B) apply() passes arguments as a list, call() passes them as an array
o C) Both are identical
o D) Neither are valid methods
162. What is the purpose of Immediately Invoked Function Expressions (IIFE)?
o A) To create a new scope
o B) To execute code immediately
o C) To prevent variable pollution in the global scope
o D) All of the above
163. Which method returns a new array with all elements that pass the test implemented by the provided function?
o A) map()
o B) filter()
o C) reduce()
o D) forEach()
164. What is the purpose of the reduce() method?
o A) To iterate over an array without returning a result
o B) To transform each element of an array
o C) To accumulate a single value from an array
o D) To filter elements of an array
165. How can you clone an array arr in ES6?
o A) let clone = arr.slice();
o B) let clone = [...arr];
o C) let clone = Array.from(arr);
o D) All of the above
166. What is the purpose of the Symbol type introduced in ES6?
o A) To create unique identifiers for object properties
o B) To handle asynchronous operations
o C) To work with regular expressions
o D) To create immutable objects
167. Which of the following is NOT a valid way to create a new Set in JavaScript?
o A) new Set([1, 2, 3])
o B) Set.of(1, 2, 3)
o C) Set.create(1, 2, 3)
o D) new Set()
168. What is a WeakMap in JavaScript?
o A) A collection of key-value pairs where keys are objects and values can be arbitrary values
o B) A regular Map with additional security
o C) A Map that allows garbage collection of keys if there are no other references
o D) Both A and C
169. Which feature introduced in ES6 allows objects to be extended with new properties dynamically?
o A) Proxies
o B) Object.assign()
o C) Destructuring
o D) Spread Operator
Miscellaneous Advanced Topics
171. What is the purpose of the Proxy object in JavaScript?
o A) To intercept and redefine fundamental operations for an object
o B) To create a clone of an object
o C) To handle asynchronous operations
o D) To optimize performance
172. Which of the following is used to handle asynchronous operations in JavaScript without blocking the main thread?
o A) Web Workers
o B) Callbacks
o C) Promises
o D) All of the above
173. What does the Object.freeze() method do?
o A) Makes an object immutable
o B) Prevents adding new properties
o C) Prevents deleting existing properties
o D) All of the above
174. Which statement best describes hoisting in JavaScript?
o A) Variable declarations are moved to the top of their scope before code execution
o B) Functions are executed before variables are declared
o C) Variables are always initialized at the top of the code
o D) All of the above
175. What is the purpose of the bind() method in JavaScript?
o A) To create a new function with a bound this value
o B) To attach an event listener
o C) To merge two objects
o D) To iterate over array elements
176. Which of the following is a way to create private variables in JavaScript?
o A) Using closures
o B) Using Symbols
o C) Using WeakMaps
o D) All of the above
177. What is the purpose of the yield keyword in JavaScript?
o A) To pause and resume generator functions
o B) To handle asynchronous operations
o C) To declare variables
o D) To exit loops
178. Which of the following is true about generator functions?
o A) They can return multiple values over time
o B) They are declared using the function* syntax
o C) They maintain their state between executions
o D) All of the above
180. What does the finally block do in a try...catch statement?
o A) It executes code only if an error occurs
o B) It executes code only if no error occurs
o C) It executes code regardless of whether an error occurs
o D) It rethrows the error
Miscellaneous JavaScript Concepts
181. Which of the following is NOT a JavaScript data type?
o A) Symbol
o B) BigInt
o C) Tuple
o D) Undefined
182. What is the result of typeof []?
o A) array
o B) object
o C) undefined
o D) null
183. Which of the following is true about the this keyword in JavaScript?
o A) It refers to the global object in non-strict mode
o B) It refers to the object that invoked the function
o C) Its value depends on how a function is called
o D) All of the above
184. What is the purpose of the debugger statement?
o A) To stop the execution of code
o B) To invoke any available debugging functionality
o C) To log debugging information
o D) To restart the script
185. Which of the following is used to handle exceptions in asynchronous code with async/await?
o A) .catch()
o B) try...catch
o C) throw
o D) Both A and B
186. What will console.log(typeof NaN); output?
o A) number
o B) NaN
o C) undefined
o D) object
187. Which of the following can be used to define a block scope in JavaScript?
o A) { }
o B) function() { }
o C) if statement
o D) All of the above
188. What is the purpose of the Object.entries() method?
o A) To get an array of key-value pairs from an object
o B) To get an array of keys from an object
o C) To get an array of values from an object
o D) To clone an object
189. What is the output of typeof function() {}?
o A) function
o B) object
o C) undefined
o D) string
190. Which of the following is a way to create a class in ES6?
o A) class MyClass { constructor() {} }
o B) function MyClass() {} MyClass.prototype.method = function() {};
o C) const MyClass = class { constructor() {} }
o D) All of the above
Miscellaneous JavaScript Concepts (Continued)
191. What is the result of 0 || "default" in JavaScript?
o A) 0
o B) "default"
o C) false
o D) null
192. Which method converts all elements of an array into a single value by executing a reducer function on each element?
o A) map()
o B) filter()
o C) reduce()
o D) forEach()
193. What does the Object.keys() method return?
o A) An array of an object's keys
o B) An array of an object's values
o C) An array of key-value pairs
o D) An array of symbols
194. Which of the following is true about JavaScript's single-threaded nature?
o A) It can perform multiple operations simultaneously
o B) It executes one operation at a time
o C) It uses multi-threading to handle tasks
o D) It cannot handle asynchronous operations
195. How do you define a generator function in JavaScript?
o A) function* gen() { yield 1; }
o B) function gen() { return* 1; }
o C) generator gen() { yield 1; }
o D) def* gen() { yield 1; }
196. What is the purpose of the Promise.resolve() method?
o A) To create a promise that is already resolved with a given value
o B) To convert a value to a promise
o C) Both A and B
o D) Neither A nor B
197. Which of the following is used to handle multiple asynchronous operations sequentially?
o A) Promise.all()
o B) Promise.race()
o C) Async/Await
o D) Callbacks
198. What does the Array.prototype.find() method do?
o A) Returns the index of the first element that satisfies the provided testing function
o B) Returns the first element that satisfies the provided testing function
o C) Returns all elements that satisfy the provided testing function
o D) Returns a boolean indicating if any element satisfies the provided testing function
199. How can you ensure that a piece of code runs only after the entire page has loaded?
o A) Using window.onload
o B) Using document.ready
o C) Using window.ready
o D) Using document.onload
200. What is the difference between == and === in JavaScript?
o A) == checks for value equality, === checks for both value and type equality
o B) == checks for type equality, === checks for value equality
o C) Both are identical
o D) == is deprecated
