1What is the primary function of the Execution Context in JavaScript?
A.To manage the memory heap allocation for objects.
B.To define the environment in which JavaScript code is evaluated and executed.
C.To compilation JavaScript code into machine code before execution.
D.To handle HTTP requests and responses asynchronously.
Correct Answer: To define the environment in which JavaScript code is evaluated and executed.
Explanation:The Execution Context is an abstract concept that holds information about the environment within which the current code is being executed, including the this binding, variable environment, and scope chain.
Incorrect! Try again.
2In the context of the Scope Chain, what happens when a variable is not found in the immediate local scope?
A.The engine throws a ReferenceError immediately.
B.The engine declares the variable in the local scope automatically.
C.The engine looks up the scope chain to the outer (lexical) environment.
D.The engine returns undefined.
Correct Answer: The engine looks up the scope chain to the outer (lexical) environment.
Explanation:JavaScript uses lexical scoping. If a variable is not found in the current scope, the engine traverses up the scope chain to the parent scope, continuing until it reaches the global scope or finds the variable.
Incorrect! Try again.
3Which of the following creates a Closure?
A.A function defined inside another function that accesses variables from the outer function.
B.Any function that uses global variables.
C.A function that returns a Promise.
D.A class extending another class.
Correct Answer: A function defined inside another function that accesses variables from the outer function.
Explanation:A closure is formed when a function retains access to its lexical scope (the variables defined in its outer function), even when that function is executed outside that scope.
Incorrect! Try again.
4Consider the following code snippet. What will be logged to the console?
javascript
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}
A.0, 1, 2
B.1, 2, 3
C.3, 3, 3
D.undefined, undefined, undefined
Correct Answer: 3, 3, 3
Explanation:Because var is function-scoped (or globally scoped here), there is only one shared i variable. By the time the setTimeout callbacks run, the loop has finished and i has incremented to 3.
Incorrect! Try again.
5How can the issue in the previous question (printing 3, 3, 3) be fixed to print 0, 1, 2 using ES6 syntax?
A.Use const instead of var.
B.Use let instead of var.
C.Wrap the setTimeout in a Promise.
D.Increase the timeout duration.
Correct Answer: Use let instead of var.
Explanation:let creates a block-scoped variable. In a for loop, a new binding for i is created for every iteration, so each closure captures a distinct value of i.
Incorrect! Try again.
6What is the Temporal Dead Zone (TDZ)?
A.The time between a network request and the response.
B.The period between entering a scope and the actual declaration of a let or const variable.
C.The state of a Promise before it resolves.
D.Code that is never executed in a switch statement.
Correct Answer: The period between entering a scope and the actual declaration of a let or const variable.
Explanation:Variables declared with let and const are hoisted but not initialized. Accessing them before the declaration line results in a ReferenceError due to the TDZ.
Incorrect! Try again.
7In the JavaScript Prototype Chain, if you access a property on an object, where does the engine look first?
A.It looks at Object.prototype.
B.It looks at the object's own properties.
C.It looks at the object's __proto__.
D.It looks at the Global object.
Correct Answer: It looks at the object's own properties.
Explanation:The lookup process starts with the object's own properties. If not found, it traverses up the prototype chain via [[Prototype]].
Incorrect! Try again.
8What is the result of Object.getPrototypeOf(func) === Function.prototype for a standard function func?
A.true
B.false
C.undefined
D.null
Correct Answer: true
Explanation:All standard JavaScript functions inherit from Function.prototype.
Incorrect! Try again.
9Which method is used to create a new object with a specified prototype object and properties?
A.Object.new()
B.Object.make()
C.Object.create()
D.Object.construct()
Correct Answer: Object.create()
Explanation:Object.create(proto) creates a new object, using an existing object as the prototype of the newly created object.
Incorrect! Try again.
10What key component of the JavaScript runtime is responsible for handling asynchronous callbacks?
A.The Heap
B.The Call Stack
C.The Event Loop
D.The Parser
Correct Answer: The Event Loop
Explanation:The Event Loop monitors the Call Stack and the Task Queues. If the Call Stack is empty, it pushes the first task from the queue to the stack.
Incorrect! Try again.
11Is JavaScript single-threaded or multi-threaded?
A.Multi-threaded
B.Single-threaded
C.Single-threaded but processes Microtasks in parallel
D.It depends on the browser
Correct Answer: Single-threaded
Explanation:JavaScript has a single Call Stack and executes code on a single thread. Concurrency is handled via the Event Loop and Web APIs.
Incorrect! Try again.
12Which of the following is added to the Microtask Queue?
A.setTimeout callbacks
B.setInterval callbacks
C.Promise.then callbacks
D.I/O events
Correct Answer: Promise.then callbacks
Explanation:Promise callbacks (.then, .catch, .finally) and queueMicrotask are added to the Microtask Queue, which has higher priority than the Macrotask Queue.
Incorrect! Try again.
13Consider the following code. What is the order of execution?
14What are the three possible states of a Promise?
A.Start, Process, End
B.Pending, Fulfilled, Rejected
C.Waiting, Done, Error
D.Sent, Received, Failed
Correct Answer: Pending, Fulfilled, Rejected
Explanation:A Promise is essentially a state machine that starts as pending and transitions to either fulfilled (resolved) or rejected.
Incorrect! Try again.
15What does the async keyword do when placed before a function declaration?
A.It forces the function to run on a separate thread.
B.It pauses the execution of the global script.
C.It ensures the function always returns a Promise.
D.It makes the function synchronous.
Correct Answer: It ensures the function always returns a Promise.
Explanation:async functions always return a Promise. If the function returns a value, the Promise is resolved with that value; if it throws, the Promise is rejected.
Incorrect! Try again.
16How does await affect the execution context inside an async function?
A.It blocks the main thread until the Promise resolves.
B.It pauses the execution of the async function until the Promise resolves.
C.It creates a new thread for the Promise.
D.It cancels the Promise if it takes too long.
Correct Answer: It pauses the execution of the async function until the Promise resolves.
Explanation:await yields execution to the event loop, pausing the local async function, but allowing the caller and other events to continue processing.
Incorrect! Try again.
17What is the difference between Promise.all() and Promise.allSettled()?
A.Promise.all waits for all to complete regardless of result; Promise.allSettled fails if one fails.
B.Promise.all fails fast if any input promise rejects; Promise.allSettled waits for all to finish regardless of status.
C.They are identical alias methods.
D.Promise.allSettled only accepts synchronous functions.
Correct Answer: Promise.all fails fast if any input promise rejects; Promise.allSettled waits for all to finish regardless of status.
Explanation:Promise.all rejects immediately if one promise rejects. Promise.allSettled returns an array of status objects after all promises have either resolved or rejected.
Incorrect! Try again.
18In ES6, what is the behavior of the arrow function => regarding the this keyword?
A.It creates a new this scope.
B.It ignores this completely.
C.It lexically binds this (inherits it from the surrounding scope).
D.It binds this to the global object always.
Correct Answer: It lexically binds this (inherits it from the surrounding scope).
Explanation:Arrow functions do not have their own this. They capture the this value of the enclosing lexical context.
Explanation:Arrow functions do not bind their own this. In this object literal, this refers to the global/module scope (where a is not defined), not the object itself.
Incorrect! Try again.
20Which ES6 feature allows you to extract data from arrays or objects into distinct variables?
A.Concatenation
B.Destructuring assignment
C.Template literals
D.Spread syntax
Correct Answer: Destructuring assignment
Explanation:Destructuring is a syntax that allows unpacking values from arrays, or properties from objects, into distinct variables (e.g., const { x } = obj;).
Incorrect! Try again.
21What is the output of the following spread syntax usage?
Explanation:The spread operator (...) expands arr1 into individual elements within arr2.
Incorrect! Try again.
22What is the primary difference between a Map and a plain Object in ES6?
A.Objects allow keys of any type; Maps only allow strings.
B.Maps do not inherit from Object.
C.Maps allow keys of any type (including objects); Objects historically allow only strings/symbols.
D.Maps are slower than Objects.
Correct Answer: Maps allow keys of any type (including objects); Objects historically allow only strings/symbols.
Explanation:A key in a Map can be anything (function, object, primitive), whereas Object keys must be strings or symbols.
Incorrect! Try again.
23Which statement correctly exports a default value from an ES6 module?
A.export default myFunction;
B.export myFunction;
C.module.exports = myFunction;
D.default export myFunction;
Correct Answer: export default myFunction;
Explanation:export default is the standard ES6 syntax for the single default export of a module.
Incorrect! Try again.
24How do you import a named export { data } and rename it to info?
A.import { data as info } from './module';
B.import data: info from './module';
C.import { data -> info } from './module';
D.import { info } from './module';
Correct Answer: import { data as info } from './module';
Explanation:The as keyword is used in import statements to rename exports locally.
Incorrect! Try again.
25When using type="module" in a script tag, what is the default behavior regarding execution timing?
A.It blocks parsing until executed.
B.It is deferred (defer) by default.
C.It is executed asynchronously (async).
D.It executes immediately.
Correct Answer: It is deferred (defer) by default.
Explanation:ES6 modules (type="module") are automatically deferred, meaning they wait for the HTML parsing to finish before executing.
Incorrect! Try again.
26What is Hoisting?
A.Moving a DOM element to the top of the body.
B.The behavior where variable and function declarations are moved to the top of their scope during compilation.
C.Raising the priority of a thread.
D.Importing a module from a CDN.
Correct Answer: The behavior where variable and function declarations are moved to the top of their scope during compilation.
Explanation:Hoisting is the mechanism where declarations (but not initializations) appear to be moved to the top of the code.
Incorrect! Try again.
27What is the output of console.log(x) if var x = 5 is declared on the next line?
A.ReferenceError
B.5
C.undefined
D.null
Correct Answer: undefined
Explanation:var declarations are hoisted, initialized with undefined. The assignment x = 5 happens where the line is executing.
Incorrect! Try again.
28Which queue has higher priority in the Event Loop?
A.Macrotask Queue
B.Microtask Queue
C.Callback Queue
D.Render Queue
Correct Answer: Microtask Queue
Explanation:After every macrotask (and initially after script execution), the engine empties the entire Microtask Queue before moving to the next Macrotask.
Incorrect! Try again.
29What does Promise.race() do?
A.Waits for the fastest Promise to resolve.
B.Waits for the fastest Promise to settle (resolve or reject).
C.Runs all Promises in parallel and returns an array.
D.Stops the slowest Promise.
Correct Answer: Waits for the fastest Promise to settle (resolve or reject).
Explanation:Promise.race returns a promise that settles as soon as the first promise in the iterable settles (either resolves or rejects).
Incorrect! Try again.
30Which ES6 structure is best suited for maintaining a list of unique values?
A.Array
B.Map
C.Set
D.Object
Correct Answer: Set
Explanation:A Set is a collection of unique values. Attempting to add a duplicate value will have no effect.
Incorrect! Try again.
31What defines the value of this in a standard function call (not arrow, not strict mode)?
A.Where the function is declared.
B.How the function is called.
C.The type of the function.
D.The file it is located in.
Correct Answer: How the function is called.
Explanation:In standard functions, this is dynamic and determined by the call site (e.g., method invocation vs standalone call).
Incorrect! Try again.
32How can you manually set the this context for a function call?
A.Using .bind(), .call(), or .apply()
B.Using .setThis()
C.Using .context()
D.It is impossible to manually set this.
Correct Answer: Using .bind(), .call(), or .apply()
Explanation:These methods allow you to explicitly specify what object this should refer to.
Incorrect! Try again.
33What is a WeakMap?
A.A Map that only holds primitive keys.
B.A Map where keys are weakly referenced, allowing garbage collection if there are no other references to the key.
C.A Map that has limited methods.
D.A Map that is not thread-safe.
Correct Answer: A Map where keys are weakly referenced, allowing garbage collection if there are no other references to the key.
Explanation:WeakMap keys must be objects. If the object key is no longer referenced elsewhere, it can be garbage collected, removing the entry from the WeakMap.
Incorrect! Try again.
34What is the purpose of the module pattern (using IIFE and Closures) in pre-ES6 JavaScript?
A.To speed up execution.
B.To create private scope and encapsulate data.
C.To allow multi-threading.
D.To support classes.
Correct Answer: To create private scope and encapsulate data.
Explanation:Before ES6 modules, the Module Pattern used IIFEs to create a function scope, hiding private variables via closures and returning a public API.
Incorrect! Try again.
35What happens if you await a non-Promise value? e.g., await 10;
A.It throws a TypeError.
B.It returns 10 immediately.
C.It wraps the value in a resolved Promise and waits for the microtask queue.
D.It causes an infinite loop.
Correct Answer: It wraps the value in a resolved Promise and waits for the microtask queue.
Explanation:await converts non-promise values into resolved promises, causing a brief pause (microtask tick) before resuming execution.
Incorrect! Try again.
36Which of the following is an example of a Macrotask?
A.process.nextTick (Node.js)
B.Promise.resolve().then(...)
C.queueMicrotask(...)
D.setInterval(...)
Correct Answer: setInterval(...)
Explanation:setTimeout, setInterval, and setImmediate are examples of Macrotasks.
Incorrect! Try again.
37What is the output of console.log(typeof class {});?
A."class"
B."object"
C."function"
D."prototype"
Correct Answer: "function"
Explanation:Classes in ES6 are syntactic sugar over existing prototypal inheritance; under the hood, they are functions.
Incorrect! Try again.
38What is the Rest Parameter syntax?
A.function f(...args)
B.function f(args...)
C.function f($args)
D.function f(args[])
Correct Answer: function f(...args)
Explanation:The rest parameter syntax (...variable) collects all remaining arguments into an array.
Incorrect! Try again.
39What characterizes Strict Mode ('use strict') regarding this in a standalone function?
A.this defaults to the Global Object.
B.this defaults to undefined.
C.this defaults to the function itself.
D.this causes a syntax error.
Correct Answer: this defaults to undefined.
Explanation:In non-strict mode, this in a plain function call points to window/global. In strict mode, it is undefined to prevent accidental global modifications.
Incorrect! Try again.
40Why is it generally discouraged to modify Object.prototype directly?
A.It is read-only.
B.It affects every object in the application, potentially leading to conflicts.
C.It throws a security error.
D.It disables garbage collection.
Correct Answer: It affects every object in the application, potentially leading to conflicts.
Explanation:Modifying the native prototype (Monkey Patching) affects all objects inheriting from it, which can break third-party libraries or future language features.
Incorrect! Try again.
41Which ES2020 feature allows accessing deeply nested properties without checking existence at each level?
A.Nullish Coalescing (??)
B.Optional Chaining (?.)
C.Logical OR (||)
D.Object.assign
Correct Answer: Optional Chaining (?.)
Explanation:user?.address?.street returns undefined if any intermediate property is null/undefined, rather than throwing an error.
Incorrect! Try again.
42What is the purpose of the super keyword in an ES6 Class?
A.To declare a super global variable.
B.To call the constructor or methods of the parent class.
C.To define the superior method.
D.To access the DOM root.
Correct Answer: To call the constructor or methods of the parent class.
Explanation:super() calls the parent constructor, and super.method() calls a method on the parent's prototype.
Incorrect! Try again.
43What is a Generator Function?
A.A function that automatically generates random numbers.
B.A function that can be paused and resumed, declared with function*.
C.A function that creates new classes.
D.A factory function for DOM elements.
Correct Answer: A function that can be paused and resumed, declared with function*.
Explanation:Generator functions return a Generator object and use yield to pause execution and return values incrementally.
Incorrect! Try again.
44In the context of Modules, what does Tree Shaking refer to?
A.Randomizing the order of imports.
B.Removing unused code (dead code elimination) during the build process.
C.Refreshing the browser automatically.
D.Structuring the folder hierarchy.
Correct Answer: Removing unused code (dead code elimination) during the build process.
Explanation:Modern bundlers use the static structure of ES6 modules to detect and remove exports that are not imported anywhere.
Incorrect! Try again.
45How do you create a Dynamic Import?
A.import('./module').then(...)
B.require('./module')
C.fetch('./module')
D.load('./module')
Correct Answer: import('./module').then(...)
Explanation:Dynamic imports use the function-like import() syntax, which returns a Promise that resolves to the module namespace object.
Incorrect! Try again.
46What is the output of console.log(1 + '1')?
A.2
B."11"
C.NaN
D.TypeError
Correct Answer: "11"
Explanation:JavaScript performs type coercion. When the + operator sees a string, it coerces the number to a string and concatenates.
Incorrect! Try again.
47What does the finally block in a Promise chain do?
A.It runs only if the promise is rejected.
B.It runs only if the promise is resolved.
C.It runs regardless of whether the promise was resolved or rejected.
D.It terminates the script.
Correct Answer: It runs regardless of whether the promise was resolved or rejected.
Explanation:finally() is used for cleanup code that must execute regardless of the Promise outcome.
Incorrect! Try again.
48In a closure, where are the captured variables stored?
A.On the Call Stack.
B.In the Heap.
C.In the CPU registers.
D.In LocalStorage.
Correct Answer: In the Heap.
Explanation:Closures usually outlive the execution context that created them. Therefore, captured variables are stored in the Heap so they persist after the function returns.
Incorrect! Try again.
49What is Currying?
A.Mixing multiple spices.
B.Transforming a function with multiple arguments into a sequence of functions each taking a single argument.
C.Calling a function recursively.
D.Binding this to a function.
Correct Answer: Transforming a function with multiple arguments into a sequence of functions each taking a single argument.
Explanation:Currying transforms f(a, b, c) into f(a)(b)(c).
Incorrect! Try again.
50Which symbol is used for Template Literals?
A.Single quotes '
B.Double quotes "
C.Backticks `
D.Hyphens -
Correct Answer: Backticks `
Explanation:Template literals are delimited by backticks and allow for embedded expressions ${expression} and multi-line strings.