Latest JavaScript Basics MCQs

1 min read

JavaScript is a high-level, dynamic, single-threaded interpreted programming language that powers modern interactive web applications. Key foundational concepts include dynamic typing, primitive versus reference data types, automatic type coercion, variable scoping via var, let, and const, and function declarations. Additionally, JavaScript relies on prototype-based inheritance and uses an event-driven, non-blocking execution model managed by an event loop. Mastering core JavaScript syntax, operator precedence, equality comparisons (== vs ===), and standard built-in objects like Arrays and Dictionaries is essential for front-end engineering, back-end Node.js development, and technical technical interview preparation.

1. Which method cancels a pending execution scheduled by `setTimeout()`?

a) stopTimeout()
b) clearTimeout()
c) cancelTimeout()
d) abortTimeout()
Correct Answer: b) clearTimeout()
Explanation:
clearTimeout() takes the timer identifier returned by setTimeout() and cancels its execution.

2. What is the output of `console.log(typeof function(){})`?

a) "object"
b) "function"
c) "method"
d) "undefined"
Correct Answer: b) "function"
Explanation:
In JavaScript, although functions are technically callable objects, typeof returns "function" for them.

3. Which operator performs a bitwise AND operation in JavaScript?

a) &&
b) &
c) and
d) BIT_AND
Correct Answer: b) &
Explanation:
The single ampersand `&` is used for bitwise AND, whereas `&&` is used for logical AND.

4. Which operator performs a bitwise OR operation in JavaScript?

a) ||
b) |
c) or
d) BIT_OR
Correct Answer: b) |
Explanation:
The single pipe `|` performs a bitwise OR operation across corresponding bits of its operands.

5. Which operator performs a bitwise XOR operation in JavaScript?

a) ^
b) ^^
c) ~
d) **
Correct Answer: a) ^
Explanation:
The caret `^` operator performs a bitwise XOR (exclusive OR) operation on two operands.

6. Which operator performs a bitwise NOT operation in JavaScript?

a) !
b) ~
c) NOT
d) !!
Correct Answer: b) ~
Explanation:
The tilde `~` operator inverts all the bits of its operand (bitwise NOT).

7. What will `console.log(10 % 3)` evaluate to?

a) 3
b) 1
c) 0
d) 3.33
Correct Answer: b) 1
Explanation:
The remainder operator `%` returns the remainder left over when one operand is divided by a second operand (10 / 3 = 3 remainder 1).

8. Which statement best describes the execution context in JavaScript?

a) The physical server where the code runs
b) An environment in which JavaScript code is evaluated and executed
c) The HTML file containing the script tag
d) The memory limit set by the browser
Correct Answer: b) An environment in which JavaScript code is evaluated and executed
Explanation:
An execution context is an abstract concept that holds information about the environment within which the current code is being executed.

9. Which component manages the call stack and callback queue in JavaScript engine?

a) Event Loop
b) Garbage Collector
c) Just-In-Time Compiler
d) DOM Parser
Correct Answer: a) Event Loop
Explanation:
The Event Loop continuously checks if the Call Stack is empty and moves asynchronous callbacks from the Task Queue to the Call Stack.

10. Promises and MutationObserver callbacks belong to which queue in the Event Loop?

a) Macrotask Queue
b) Microtask Queue
c) Render Queue
d) Call Queue
Correct Answer: b) Microtask Queue
Explanation:
Promise reactions (.then/.catch/await) and MutationObserver callbacks are processed in the Microtask Queue, which takes priority over Macrotasks.

11. Which of the following is executed as a Macrotask (Task)?

a) Promise.resolve()
b) setTimeout() callback
c) queueMicrotask()
d) process.nextTick()
Correct Answer: b) setTimeout() callback
Explanation:
setTimeout, setInterval, and I/O callbacks are categorized as Macrotasks.

12. What is the result of `"hello".charAt(1)`?

a) "h"
b) "e"
c) "l"
d) "o"
Correct Answer: b) "e"
Explanation:
Strings are 0-indexed in JavaScript. Index 0 is 'h' and index 1 is 'e'.

13. Which String method converts a string to all lowercase letters?

a) toLowerCase()
b) toSmall()
c) lower()
d) changeLower()
Correct Answer: a) toLowerCase()
Explanation:
toLowerCase() returns the calling string value converted to lower case.

14. Which String method converts a string to all uppercase letters?

a) toUpper()
b) toUpperCase()
c) capitalize()
d) changeUpper()
Correct Answer: b) toUpperCase()
Explanation:
toUpperCase() returns the calling string value converted to uppercase.

15. Which method determines whether a string begins with the characters of a specified string?

a) startsWith()
b) beginsWith()
c) hasStart()
d) includesStart()
Correct Answer: a) startsWith()
Explanation:
startsWith() determines whether a string begins with the characters of a specified string, returning true or false.

16. Which method determines whether a string ends with the characters of a specified string?

a) endsWith()
b) hasEnd()
c) isEnding()
d) finishWith()
Correct Answer: a) endsWith()
Explanation:
endsWith() determines whether a string ends with the characters of a specified string.

17. Which String method replaces occurrences of a search value with a replacement value?

a) swap()
b) replace()
c) change()
d) modify()
Correct Answer: b) replace()
Explanation:
replace() returns a new string with one, some, or all matches of a pattern replaced by a replacement.

18. Which method replaces ALL occurrences of a pattern in a string without using regular expressions?

a) replaceAll()
b) replaceEvery()
c) substituteAll()
d) cleanAll()
Correct Answer: a) replaceAll()
Explanation:
replaceAll() returns a new string with all matches of a pattern replaced by a replacement.

19. What will `console.log(Array.from("123"))` return?

a) ["123"]
b) ["1", "2", "3"]
c) [1, 2, 3]
d) 123
Correct Answer: b) ["1", "2", "3"]
Explanation:
Array.from() creates a new array from an iterable object, splitting the string into individual character elements.

20. Which property returns the length of a JavaScript string or array?

a) count
b) size
c) length
d) index
Correct Answer: c) length
Explanation:
The `.length` property reflects the number of elements in an array or characters in a string.

21. What is the primary function of `Object.keys(obj)`?

a) Returns an array of an object's enumerable property names
b) Returns an array of an object's property values
c) Returns key-value pairs as nested arrays
d) Locks an object from editing
Correct Answer: a) Returns an array of an object's enumerable property names
Explanation:
Object.keys() returns an array of a given object's own enumerable property names.

22. What is the primary function of `Object.values(obj)`?

a) Returns an array of property keys
b) Returns an array of an object's own enumerable string-keyed property values
c) Deletes all values in an object
d) Validates data types of object values
Correct Answer: b) Returns an array of an object's own enumerable string-keyed property values
Explanation:
Object.values() returns an array containing the values of all own enumerable properties of an object.

23. What does `Object.entries(obj)` return?

a) An array of key names
b) An array of value items
c) An array of an object's own enumerable string-keyed property [key, value] pairs
d) A Map instance
Correct Answer: c) An array of an object's own enumerable string-keyed property [key, value] pairs
Explanation:
Object.entries() returns an array of a given object's own enumerable string-keyed property [key, value] pairs.

24. Which method copies all enumerable own properties from one or more source objects to a target object?

a) Object.copy()
b) Object.assign()
c) Object.clone()
d) Object.merge()
Correct Answer: b) Object.assign()
Explanation:
Object.assign() copies all enumerable own properties from one or more source objects to a target object and returns the target object.

25. Which method prevents new properties from being added to an object and prevents existing properties from being removed or modified?

a) Object.seal()
b) Object.freeze()
c) Object.preventExtensions()
d) Object.lock()
Correct Answer: b) Object.freeze()
Explanation:
Object.freeze() freezes an object: preventing new properties from being added, existing properties from being removed, and existing values from being changed.

26. Which method prevents adding new properties to an object and marks existing properties as non-configurable (but values can still be changed if writable)?

a) Object.freeze()
b) Object.seal()
c) Object.protect()
d) Object.stop()
Correct Answer: b) Object.seal()
Explanation:
Object.seal() seals an object, preventing new properties from being added and marking existing ones non-configurable, though existing writable values can still be mutated.

27. How can you check if an object is frozen using a built-in method?

a) Object.isFrozen(obj)
b) obj.isFrozen()
c) Object.checkFreeze(obj)
d) Object.hasFrozen(obj)
Correct Answer: a) Object.isFrozen(obj)
Explanation:
Object.isFrozen() determines if an object is frozen.

28. What is the prototype of a standard object literal `{}` by default?

a) null
b) Object.prototype
c) Function.prototype
d) undefined
Correct Answer: b) Object.prototype
Explanation:
All standard object literals inherit directly from Object.prototype.

29. How do you create an object with NO prototype (pure dictionary object)?

a) Object.create(null)
b) new Object(null)
c) { prototype: null }
d) Object.define(null)
Correct Answer: a) Object.create(null)
Explanation:
Object.create(null) creates a clean object with no prototype chain attached.

30. Which method checks if an object has a specified property as its OWN property (not inherited)?

a) Object.prototype.hasOwnProperty()
b) Object.contains()
c) Object.includes()
d) Object.hasProperty()
Correct Answer: a) Object.prototype.hasOwnProperty()
Explanation:
hasOwnProperty() returns a boolean indicating whether the object has the specified property as its own property.

31. Which static method recommended in ES2022 safely checks own properties without relying on `Object.prototype`?

a) Object.hasOwn(obj, prop)
b) Object.isOwn(obj, prop)
c) Object.checkOwn(obj, prop)
d) Object.owns(obj, prop)
Correct Answer: a) Object.hasOwn(obj, prop)
Explanation:
Object.hasOwn() is a static method introduced to replace hasOwnProperty() for safer property checking on objects created without prototype.

32. What does the `this` keyword refer to inside a regular function in non-strict global context (in browser)?

a) undefined
b) The window object
c) The function itself
d) null
Correct Answer: b) The window object
Explanation:
In non-strict mode, `this` defaults to the global object (`window` in browser context).

33. What does the `this` keyword evaluate to inside a regular function in strict mode global context?

a) window
b) undefined
c) null
d) globalThis
Correct Answer: b) undefined
Explanation:
In strict mode, default binding for `this` inside functions is set to `undefined`.

34. Which function invocation method allows passing arguments as an array?

a) call()
b) apply()
c) bind()
d) execute()
Correct Answer: b) apply()
Explanation:
apply() calls a function with a given `this` value, and arguments provided as an array (or an array-like object).

35. Which function invocation method accepts an argument list individually rather than as an array?

a) apply()
b) call()
c) bind()
d) spread()
Correct Answer: b) call()
Explanation:
call() invokes a function with a given `this` value and arguments provided individually.

36. What does Function.prototype.bind() return?

a) The result of calling the original function
b) A new copy of the function with bound `this` and initial parameters
c) An array of bound variables
d) A Promise
Correct Answer: b) A new copy of the function with bound `this` and initial parameters
Explanation:
bind() creates a new bound function that wraps the original function object.

37. What is an IIFE in JavaScript?

a) Internal Interface Functional Engine
b) Immediately Invoked Function Expression
c) Iterative Input File Execution
d) Instance Inherited Function Entity
Correct Answer: b) Immediately Invoked Function Expression
Explanation:
An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.

38. Which of the following represents a valid syntax for an IIFE?

a) (function() {})();
b) function() {}();
c) function iife() => ();
d) new function()();
Correct Answer: a) (function() {})();
Explanation:
Grouping parentheses `()` wrap the function declaration turning it into an expression, followed by `()` to invoke it immediately.

39. What is the primary purpose of using an IIFE?

a) To speed up loop iterations
b) To create a private scope and avoid polluting the global namespace
c) To bind a class constructor
d) To handle asynchronous fetch calls
Correct Answer: b) To create a private scope and avoid polluting the global namespace
Explanation:
IIFEs isolate variable declarations inside their block scope, preventing global scope pollution.

40. Which operator returns `true` if an object is an instance of a specific class or constructor?

a) typeof
b) instanceof
c) isPrototypeOf
d) typeOf
Correct Answer: b) instanceof
Explanation:
The instanceof operator tests whether the prototype property of a constructor appears anywhere along the prototype chain of an object.

41. What will `console.log([] instanceof Array)` return?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
Array literal `[]` inherits directly from `Array.prototype`, so `[] instanceof Array` evaluates to true.

42. What will `console.log([] instanceof Object)` return?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
Because `Array.prototype` inherits from `Object.prototype`, arrays are also instances of Object.

43. Which object standard property provides a cross-environment reference to the global object?

a) window
b) global
c) globalThis
d) ROOT
Correct Answer: c) globalThis
Explanation:
globalThis provides a standard way to access the global scope across browsers, Node.js, and web workers.

44. What will `console.log(typeof NaN === "number")` output?

a) true
b) false
c) undefined
d) NaN
Correct Answer: a) true
Explanation:
In JavaScript, `typeof NaN` returns the string "number", making the expression true.

45. What is the result of `NaN === NaN`?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: b) false
Explanation:
NaN is the only value in JavaScript that is not equal to itself; `NaN === NaN` is false.

46. Which method accurately checks if a value is `NaN` without unexpected coercion rules?

a) isNaN()
b) Number.isNaN()
c) Math.isNaN()
d) Object.isNaN()
Correct Answer: b) Number.isNaN()
Explanation:
Number.isNaN() checks whether the passed value is NaN and its type is Number, avoiding automatic string-to-number coercion of global isNaN().

47. What does `Object.is(-0, +0)` return?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: b) false
Explanation:
Object.is() treats -0 and +0 as distinct values, returning false.

48. What does `Object.is(NaN, NaN)` return?

a) false
b) true
c) undefined
d) NaN
Correct Answer: b) true
Explanation:
Unlike strict equality (===), Object.is(NaN, NaN) evaluates to true.

49. What is a generator function in JavaScript?

a) A function that generates random numbers
b) A function that can be paused and resumed, returning an Iterator
c) A function that creates HTML elements
d) A constructor function for objects
Correct Answer: b) A function that can be paused and resumed, returning an Iterator
Explanation:
Generator functions are declared with `function*` and yield values sequentially using the `yield` keyword.

50. Which keyword is used to pause execution inside a generator function?

a) pause
b) wait
c) yield
d) stop
Correct Answer: c) yield
Explanation:
The yield keyword pauses generator function execution and returns the value of the expression following the keyword.

51. Which method is called on an Iterator returned by a generator to continue execution?

a) continue()
b) next()
c) resume()
d) step()
Correct Answer: b) next()
Explanation:
Calling `.next()` resumes generator execution until the next `yield` or `return` statement.

52. What shape of object does the `.next()` method of a generator iterator return?

a) { value: any, done: boolean }
b) { result: any, status: string }
c) [ value, done ]
d) { data: any, finished: boolean }
Correct Answer: a) { value: any, done: boolean }
Explanation:
The Iterator protocol dictates that .next() returns an object containing `value` and a boolean `done` property.

53. Which symbol makes an object iterable in JavaScript?

a) Symbol.iterator
b) Symbol.iterable
c) Symbol.loop
d) Symbol.forEach
Correct Answer: a) Symbol.iterator
Explanation:
The well-known symbol Symbol.iterator specifies the default iterator for an object used by `for...of` loops.

54. Which loop statement iterates over the ENUMERABLE PROPERTY KEYS of an object?

a) for...of
b) for...in
c) forEach()
d) while
Correct Answer: b) for...in
Explanation:
The `for...in` statement iterates over all enumerable string properties of an object (including inherited ones).

55. Which loop statement iterates over the VALUES of an iterable object (like Arrays, Sets, Maps)?

a) for...in
b) for...of
c) for...each
d) do...while
Correct Answer: b) for...of
Explanation:
The `for...of` statement creates a loop iterating over iterable objects, invoking custom iteration hooks with values.

56. What will `for (let x in [10, 20])` output as values for `x`?

a) 10, 20
b) "0", "1"
c) 1, 2
d) undefined, undefined
Correct Answer: b) "0", "1"
Explanation:
for...in iterates over array indices (keys), which are string numbers "0" and "1".

57. What will `for (let x of [10, 20])` output as values for `x`?

a) 10, 20
b) "0", "1"
c) 0, 1
d) [10, 20]
Correct Answer: a) 10, 20
Explanation:
for...of iterates over values directly, producing 10 and then 20.

58. What is a WeakMap in JavaScript?

a) A Map where keys must be objects and are held weakly (garbage collectable)
b) A Map with limited number of entries
c) A Map that can only hold string values
d) A read-only version of Map
Correct Answer: a) A Map where keys must be objects and are held weakly (garbage collectable)
Explanation:
A WeakMap is a collection of key/value pairs in which the keys MUST be objects and are held as weak references.

59. Are WeakMap keys enumerable?

a) Yes
b) No, WeakMaps are non-enumerable and cannot be iterated
c) Only in strict mode
d) Only when using for...of
Correct Answer: b) No, WeakMaps are non-enumerable and cannot be iterated
Explanation:
Because keys are weakly held, there is no list of keys maintained, making iteration impossible.

60. What is a WeakSet in JavaScript?

a) A Set that allows duplicate elements
b) A Set that stores weakly held objects
c) A Set of numbers and strings only
d) A non-mutable Set
Correct Answer: b) A Set that stores weakly held objects
Explanation:
WeakSet objects are collections of garbage-collectable objects where each object may occur only once.

61. Which mechanism removes unreachable objects from memory automatically in JavaScript?

a) Memory Deallocator
b) Garbage Collector
c) Task Runner
d) Scope Resolver
Correct Answer: b) Garbage Collector
Explanation:
JavaScript engines use automatic Garbage Collection (primarily Mark-and-Sweep) to reclaim allocated memory.

62. What is a memory leak in JavaScript?

a) When a script uses all available CPU power
b) When allocated memory is no longer needed by application but is not freed by garbage collector
c) When variables are cleared too fast
d) When JSON fails to parse
Correct Answer: b) When allocated memory is no longer needed by application but is not freed by garbage collector
Explanation:
A memory leak occurs when pieces of memory assigned to variables/objects are retained unnecessarily.

63. What does `console.log(1 == true)` output?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: a) true
Explanation:
The loose equality operator coercively converts `true` to number `1` during comparison.

64. What does `console.log(2 == true)` output?

a) true
b) false
c) TypeError
d) undefined
Correct Answer: b) false
Explanation:
`true` coerces to 1, so `2 == 1` evaluates to false.

65. What does `Promise.all()` do if one of the input Promises rejects?

a) Waits for all others and returns fulfilled results along with error
b) Immediately rejects with the reason of the first rejected promise
c) Ignores the error and resolves fulfilled ones
d) Retries the failed promise
Correct Answer: b) Immediately rejects with the reason of the first rejected promise
Explanation:
Promise.all() fails fast: if any passed promise rejects, it immediately rejects with that error.

66. Which method returns a promise that resolves or rejects as soon as ANY of the input promises settles?

a) Promise.race()
b) Promise.all()
c) Promise.any()
d) Promise.allSettled()
Correct Answer: a) Promise.race()
Explanation:
Promise.race() resolves or rejects as soon as one of the promises in an iterable resolves or rejects.

67. Which method resolves as soon as ANY of the input promises FULFILLS (ignoring rejections unless all reject)?

a) Promise.race()
b) Promise.any()
c) Promise.all()
d) Promise.first()
Correct Answer: b) Promise.any()
Explanation:
Promise.any() takes an iterable of promises and returns a single promise that resolves as soon as any of the promises fulfills.

68. Which method waits for ALL promises to complete (either fulfilled or rejected) and returns an array of status objects?

a) Promise.all()
b) Promise.allSettled()
c) Promise.any()
d) Promise.completeAll()
Correct Answer: b) Promise.allSettled()
Explanation:
Promise.allSettled() returns a promise that resolves after all of the given promises have either fulfilled or rejected.

69. What error type is thrown when attempting to modify a read-only variable or invoke invalid operations?

a) SyntaxError
b) TypeError
c) ReferenceError
d) RangeError
Correct Answer: b) TypeError
Explanation:
TypeError represents an error when a value is not of the expected type or operation is inappropriate.

70. What error type is thrown when a variable that does not exist in current scope is referenced?

a) ReferenceError
b) TypeError
c) SyntaxError
d) URIError
Correct Answer: a) ReferenceError
Explanation:
ReferenceError is thrown when attempting to reference a variable that has not been declared.

71. What error type is thrown when code violates language syntax rules?

a) SyntaxError
b) EvalError
c) TypeError
d) LogicalError
Correct Answer: a) SyntaxError
Explanation:
SyntaxError is thrown when trying to interpret syntactically invalid code.

72. What error type is thrown when a numeric value or array length is outside allowed bounds?

a) RangeError
b) BoundsError
c) LimitError
d) OverflowError
Correct Answer: a) RangeError
Explanation:
RangeError indicates an error when a value is not in the set or range of allowed values (e.g., `new Array(-1)`).

73. What does the dynamic import function `import(modulePath)` return?

a) The raw script text
b) A Promise resolving to the module object
c) A synchronous module object
d) undefined
Correct Answer: b) A Promise resolving to the module object
Explanation:
Dynamic import syntax `import()` loads modules asynchronously and returns a Promise.

74. Which keyword exports values from ES6 modules?

a) export
b) public
c) expose
d) module.out
Correct Answer: a) export
Explanation:
The `export` statement is used when creating JavaScript modules to export functions, objects, or primitive values.

75. Which keyword imports functions/variables exported from another module?

a) require
b) import
c) include
d) fetch
Correct Answer: b) import
Explanation:
The `import` static statement is used to import read-only live bindings exported by another module.

76. What module system uses `module.exports` and `require()` natively?

a) ES Modules (ESM)
b) CommonJS (CJS)
c) AMD
d) UMD
Correct Answer: b) CommonJS (CJS)
Explanation:
CommonJS is the module standard historically used in Node.js relying on `require` and `module.exports`.

77. Which API provides a modern alternative to XMLHttpRequest for network requests?

a) axios
b) fetch()
c) http.request()
d) ajax()
Correct Answer: b) fetch()
Explanation:
The Fetch API is a modern, native browser interface for fetching resources asynchronously using Promises.

78. What does `fetch(url)` return initially?

a) JSON data
b) A Promise resolving to a Response object
c) Text content
d) An XML Document
Correct Answer: b) A Promise resolving to a Response object
Explanation:
fetch() returns a Promise that resolves to the Response object representing the response to the request.

79. How do you extract JSON body data from a `fetch()` Response object `res`?

a) res.json()
b) JSON.parse(res)
c) res.body.toJSON()
d) res.getJSON()
Correct Answer: a) res.json()
Explanation:
The `.json()` method on the Response interface reads the response stream to completion and returns a Promise resolving to JSON data.

80. Which browser object enables saving key-value pairs persistently across browser sessions?

a) sessionStorage
b) localStorage
c) cookieStorage
d) indexedStorage
Correct Answer: b) localStorage
Explanation:
localStorage data persists even when the browser window/tab is closed and reopened.

81. Which storage object clears data automatically when the page session/tab ends?

a) localStorage
b) sessionStorage
c) cacheStorage
d) globalStorage
Correct Answer: b) sessionStorage
Explanation:
sessionStorage maintains a separate storage area for each given origin that is available for the duration of the page session.

82. What is the key limitation on data types stored in `localStorage`?

a) Only objects can be stored
b) Keys and values must be strings
c) Only numbers can be stored
d) Data must be encrypted
Correct Answer: b) Keys and values must be strings
Explanation:
localStorage stores key-value pairs strictly as UTF-16 strings; objects must be stringified with JSON.stringify().

83. How do you clear all items from `localStorage`?

a) localStorage.removeAll()
b) localStorage.clear()
c) localStorage.delete()
d) localStorage.reset()
Correct Answer: b) localStorage.clear()
Explanation:
localStorage.clear() removes all key/value pairs stored for that origin domain.

84. Which web feature lets JavaScript run scripts in background threads without blocking UI performance?

a) Web Workers
b) Service Handlers
c) Async Containers
d) Event Listeners
Correct Answer: a) Web Workers
Explanation:
Web Workers allow background tasks to run on separate threads off the main UI rendering thread.

85. Can Web Workers directly manipulate the DOM?

a) Yes, completely
b) No, they have no access to the `document` or DOM directly
c) Yes, but only in strict mode
d) Only when attached to window
Correct Answer: b) No, they have no access to the `document` or DOM directly
Explanation:
Web Workers run in a different global context and do not have access to DOM objects like `document`.

86. Which global method communicates data back from a Web Worker to the main thread?

a) send()
b) postMessage()
c) emit()
d) transfer()
Correct Answer: b) postMessage()
Explanation:
The postMessage() method sends messages between the worker thread and main thread.

87. What is the purpose of `Object.defineProperty()`?

a) To add or modify a property on an object with precise descriptors (configurable, writable, enumerable)
b) To print property definitions
c) To convert object into array
d) To define prototype constructor
Correct Answer: a) To add or modify a property on an object with precise descriptors (configurable, writable, enumerable)
Explanation:
Object.defineProperty() defines a new property directly on an object or modifies an existing one, controlling property behavior.

88. By default, properties added using `Object.defineProperty()` are:

a) writable, enumerable, and configurable
b) not writable, not enumerable, and not configurable
c) writable but non-enumerable
d) enumerable but non-configurable
Correct Answer: b) not writable, not enumerable, and not configurable
Explanation:
When using Object.defineProperty(), property descriptors default to false unless explicitly specified true.

89. Which concept allows intercepting and customizing operations performed on objects (like get, set, delete)?

a) Proxy
b) Reflection
c) Decorator
d) Adapter
Correct Answer: a) Proxy
Explanation:
The Proxy object enables you to create a wrapper for another object, which can intercept and redefine fundamental operations for that object.

90. In a JavaScript `Proxy`, what is the object containing handler trap functions called?

a) Target
b) Handler
c) Receiver
d) Interceptor
Correct Answer: b) Handler
Explanation:
A Proxy is instantiated using `new Proxy(target, handler)`, where `handler` holds trap methods like `get` and `set`.

91. Which built-in object provides methods for inspectable and interceptable JavaScript operations, often used inside Proxy traps?

a) Reflect
b) Mirror
c) Inspect
d) Shadow
Correct Answer: a) Reflect
Explanation:
Reflect is a built-in object that provides methods for interceptable JavaScript operations corresponding to Proxy traps.

92. What will `console.log(typeof BigInt(123))` output?

a) "number"
b) "bigint"
c) "object"
d) "largeint"
Correct Answer: b) "bigint"
Explanation:
BigInt is a primitive data type introduced to represent integers larger than 2^53 - 1.

93. How do you define a BigInt literal in JavaScript?

a) 123b
b) 123n
c) 123L
d) big(123)
Correct Answer: b) 123n
Explanation:
A BigInt literal is created by appending `n` to the end of an integer.

94. Can you mix `BigInt` and standard `Number` types directly in mathematical operations without explicit conversion?

a) Yes, always
b) No, it throws a TypeError
c) Yes, but results in NaN
d) Only when dividing
Correct Answer: b) No, it throws a TypeError
Explanation:
You cannot mix BigInt and regular Number types in operations; explicit conversion is required.

95. Which operator assigns a value to a variable ONLY if that variable is currently nullish (`null` or `undefined`)?

a) ||=
b) &&=
c) ??=
d) ?=
Correct Answer: c) ??=
Explanation:
The logical nullish assignment operator `??=` only assigns if the target evaluates to null or undefined.

96. What will `let x = 0; x ||= 10; console.log(x);` output?

a) 0
b) 10
c) undefined
d) NaN
Correct Answer: b) 10
Explanation:
Logical OR assignment `||=` assigns when the target is falsy; `0` is falsy, so `x` becomes 10.

97. What will `let x = 0; x ??= 10; console.log(x);` output?

a) 0
b) 10
c) null
d) undefined
Correct Answer: a) 0
Explanation:
Nullish assignment `??=` only assigns if target is null/undefined; `0` is neither, so `x` remains 0.

98. Which method returns a deep copy of an object natively in modern browsers and Node.js?

a) Object.clone()
b) structuredClone()
c) JSON.deepCopy()
d) Object.deepAssign()
Correct Answer: b) structuredClone()
Explanation:
structuredClone() creates a deep clone of a given value using the structured clone algorithm.

99. What happens when you parse invalid JSON string using `JSON.parse()`?

a) Returns null
b) Returns undefined
c) Throws a SyntaxError
d) Returns empty object {}
Correct Answer: c) Throws a SyntaxError
Explanation:
If the string to parse is not valid JSON, JSON.parse() throws a SyntaxError.

100. Which method creates a new array with all sub-array elements concatenated recursively up to specified depth?

a) flat()
b) flatMap()
c) compress()
d) flatten()
Correct Answer: a) flat()
Explanation:
The flat(depth) method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

101. What does `[1, [2, [3]]].flat(2)` return?

a) [1, 2, [3]]
b) [1, 2, 3]
c) [1, [2, 3]]
d) [[1, 2, 3]]
Correct Answer: b) [1, 2, 3]
Explanation:
Specifying depth 2 flattens nested arrays two levels deep, resulting in a single flat array `[1, 2, 3]`.

102. Which method flattens the result of a mapping function by 1 level?

a) mapFlat()
b) flatMap()
c) mapAndConcat()
d) deepMap()
Correct Answer: b) flatMap()
Explanation:
flatMap() applies a function to each element and flattens the result by one level.
← Previous: Latest Java OOP MCQs
Next →: Latest Python Dictionaries MCQs
JavaScript Arrays MCQs

JavaScript Arrays MCQs for Developer Interviews & Certification

Arrays in JavaScript are high-level, list-like objects used to store ordered collections of elements of varying data types. Zero-indexed and…

By MCQs Generator
Top Python Fundamentals MCQs & Answers for Beginners

Top Python Fundamentals MCQs & Answers for Beginners

Python is a dynamically typed, high-level programming language created by Guido van Rossum in 1991. Renowned for its clear syntax…

By MCQs Generator
Python Modules & Packages MCQs

Python Modules & Packages MCQs

Python modules are single files containing Python code (functions, classes, and variables) that can be imported and reused across different…

By MCQs Generator