-
1Which keyword declares a block-scoped variable in modern JavaScript?
Why: `let` declares a binding scoped to its enclosing block. A `var` declaration is scoped to a function body or, outside a function, to its surrounding script or module context rather than an ordinary block. Both forms have declaration-instantiation behavior before execution, but accessing a `let` binding before its declaration is evaluated triggers the temporal dead zone rather than returning `undefined`.
-
2Which statement best describes JavaScript's strict equality operator (`===`)?
- AIt converts both operands to strings before comparing them
- BIt compares without implicit type conversion, so operands of different types are normally unequalCorrect
- CIt checks only whether the operands have the same type
- DIt performs a deep comparison of object properties
Why: Strict equality compares operands without converting one type into another, so `5 === "5"` is false. Values of the same primitive type follow that type's equality rules; two distinct objects are unequal even if their properties look identical because objects compare by identity. It is therefore more precise than saying the operator always checks a generic 'value and type equality.'
-
3What is a closure in JavaScript?
- AA way to close the browser window
- BA function that retains access to its outer scope after the outer function has returnedCorrect
- CA method to terminate a loop
- DA syntax for defining classes
Why: A closure is a function that remembers and can access variables from its lexical scope even when the function is executed outside that scope. Closures are fundamental to patterns like module encapsulation, callbacks, and factory functions in JavaScript.
-
4Which method converts a JSON string into a JavaScript object?
- AJSON.stringify()
- BJSON.parse()Correct
- CJSON.decode()
- DJSON.convert()
Why: JSON.parse() takes a JSON-formatted string and converts it into a JavaScript object or value. Its counterpart, JSON.stringify(), does the reverse — converting a JavaScript object into a JSON string. These two methods together enable round-trip serialization.
-
5What is the output of 'typeof null' in JavaScript?
- A'null'
- B'undefined'
- C'object'Correct
- D'boolean'
Why: typeof null returns 'object', which is a well-known quirk and historical bug in JavaScript. It has been kept for backwards compatibility since fixing it would break existing code. To properly check for null, use strict equality: value === null.
-
6What happens if you try to reassign a variable declared with 'const'?
- AThe reassignment succeeds silently
- BIt throws a TypeError, because 'const' bindings cannot be reassignedCorrect
- CThe variable is automatically converted to 'let'
- DNothing happens and the value stays the same
Why: A variable declared with 'const' cannot be reassigned to a new value — attempting it throws a TypeError. Note that 'const' makes the binding constant, not the value: if a const holds an object or array you can still mutate its contents (for example, push to the array); you simply cannot point the variable at something else.
-
7Which array method returns a new array containing the results of calling a function on every element?
- AforEach()
- Bmap()Correct
- Cfilter()
- Dreduce()
Why: `Array.prototype.map()` creates a new array by applying a callback to each element and collecting the return values. The `map()` operation itself does not replace elements in the source array, although callback code can still mutate the source or objects referenced by it. `forEach()` returns `undefined`, `filter()` selects elements, and `reduce()` accumulates a result.
-
8What does a JavaScript Promise represent?
- AA guarantee that code will never throw an error
- BThe eventual result of an asynchronous operation, which may resolve or rejectCorrect
- CA way to pause the entire program until data loads
- DA special type of loop for repeated tasks
Why: A Promise represents the eventual completion or failure of an asynchronous operation. It starts pending and later becomes fulfilled or rejected. 'Resolved' is broader than 'fulfilled': a promise can be resolved to follow another still-pending promise. Handlers can be registered with `.then()` and `.catch()`, while `async`/`await` provides syntax built on promises.
-
9What is the difference between 'undefined' and 'null' in JavaScript?
- AThey are identical and fully interchangeable
- B'undefined' means a variable was declared but not assigned a value; 'null' is an intentional 'no value' assigned by the programmerCorrect
- C'null' is a syntax error while 'undefined' is valid
- D'undefined' is only for numbers and 'null' only for strings
Why: 'undefined' usually means a variable has been declared but not yet given a value (or a function returned nothing). 'null' is a value that represents the intentional absence of any object value — a programmer deliberately setting 'nothing.' For comparison, 'undefined == null' is true with loose equality, but 'undefined === null' is false because their types differ.
-
10In the expression 'const combined = [...a, ...b]', what does the spread operator (...) do?
- AIt subtracts array b from array a
- BIt expands the elements of arrays a and b into a new combined arrayCorrect
- CIt creates a reference so that changes to a also change combined
- DIt sorts the elements of both arrays
Why: In an array literal, spread syntax expands iterable values into a new array, so `[...a, ...b]` contains the elements of `a` followed by those of `b`. The copy is shallow: nested objects remain shared references. Object spread is related syntax that copies own enumerable properties into a new object; an ordinary object does not have to be iterable for object spread to work.