JavaScript ES6 Features MCQs

1 min read

ECMAScript 2015 (commonly known as ES6) marked a massive evolutionary leap for JavaScript, introducing syntax enhancements that made code cleaner, more modular, and easier to scale. Core additions included block-scoped variable declarations (let and const), concise arrow functions (() => {}), template literals with backticks, and destructuring assignments for arrays and objects. Furthermore, ES6 expanded the core language toolkit with rest/spread operators (...), default parameters, classes, and native asynchronous support through Promises. Mastering these modern syntax conventions is critical for efficient front-end development and technical software engineering interviews.

1. What is the primary difference in scoping behavior between 'var' and 'let' in ES6?

a) var is block-scoped, whereas let is function-scoped.
b) let is block-scoped, whereas var is function-scoped.
c) Both let and var are global-scoped by default.
d) let cannot be reassigned under any circumstances.
Correct Answer: b) let is block-scoped, whereas var is function-scoped.
Explanation:
Variables declared with 'let' are scoped to the nearest enclosing block, whereas 'var' declarations are scoped to the containing function or global scope.

2. What happens when you attempt to access a 'let' or 'const' variable before its declaration in the same scope?

a) It returns undefined due to hoisting.
b) It throws a ReferenceError due to the Temporal Dead Zone (TDZ).
c) It automatically initializes to null.
d) It returns a SyntaxError at compile time.
Correct Answer: b) It throws a ReferenceError due to the Temporal Dead Zone (TDZ).
Explanation:
Variables declared with let and const reside in the Temporal Dead Zone from the start of the block until the declaration is evaluated.

3. Which of the following statements is true regarding 'const' variables?

a) They cannot be reassigned, and their internal values or object properties can never be modified.
b) They cannot be reassigned, but objects and arrays assigned to them can have their properties or elements mutated.
c) They are identical to var except they must be declared inside a loop.
d) They are hoisted with an initial value of undefined.
Correct Answer: b) They cannot be reassigned, but objects and arrays assigned to them can have their properties or elements mutated.
Explanation:
const prevents variable reassignment, but properties of reference types like objects and arrays can still be mutated.

4. How do arrow functions handle the 'this' keyword compared to traditional regular functions?

a) Arrow functions define their own dynamic 'this' context based on how they are called.
b) Arrow functions lexically bind 'this', inheriting it from the surrounding enclosing execution context.
c) Arrow functions do not support the 'this' keyword entirely.
d) Arrow functions always bind 'this' to the global window object.
Correct Answer: b) Arrow functions lexically bind 'this', inheriting it from the surrounding enclosing execution context.
Explanation:
Unlike regular functions that create their own dynamic 'this' binding, arrow functions capture 'this' from their enclosing lexical scope.

5. Which of the following features is NOT supported by arrow functions?

a) Implicit return for single-line expressions
b) Lexical binding of 'this'
c) Having their own local 'arguments' object
d) Passing them as callbacks to higher-order array methods
Correct Answer: c) Having their own local 'arguments' object
Explanation:
Arrow functions do not have their own 'arguments' object; any attempt to access 'arguments' references the outer enclosing scope.

6. What is the output of evaluating template literals with expression interpolation like `const name = 'Alice'; console.log(`Hello, ${name}!`);`?

a) Hello, ${name}!
b) Hello, Alice!
c) ReferenceError
d) Undefined
Correct Answer: b) Hello, Alice!
Explanation:
Template literals enclosed by backticks allow expression interpolation using `${expression}` syntax.

7. What is array destructuring syntax used for in ES6?

a) To flatten nested multi-dimensional arrays
b) To unpack values from arrays into distinct variables in a single concise statement
c) To sort array elements in descending order
d) To delete elements from an array index
Correct Answer: b) To unpack values from arrays into distinct variables in a single concise statement
Explanation:
Array destructuring allows extracting values from arrays and assigning them to distinct variables conveniently.

8. How do you assign default values to variables during object destructuring in ES6?

a) Using the assignment operator `=` after the variable name in the destructuring pattern, e.g., `const { x = 10 } = obj;`
b) Using the `default` keyword inside the braces
c) Using colon syntax `const { x: 10 } = obj;`
d) Default values cannot be assigned during destructuring.
Correct Answer: a) Using the assignment operator `=` after the variable name in the destructuring pattern, e.g., `const { x = 10 } = obj;`
Explanation:
If the extracted property is undefined, the default value specified after the `=` operator is used.

9. What does the spread operator (`...`) do when applied to an array in an expression like `const combined = [...arr1, ...arr2];`?

a) Merges two arrays by modifying arr1 in place
b) Expands an iterable array into individual elements
c) Creates a reference to the same array memory address
d) Performs a deep clone of nested objects
Correct Answer: b) Expands an iterable array into individual elements
Explanation:
The spread operator unpacks elements from iterable collections into places where individual elements are expected.

10. What is the purpose of rest parameters (`...rest`) in function definitions?

a) To collect all remaining arguments passed to a function into a true array
b) To pause function execution asynchronously
c) To specify default values for missing arguments
d) To optimize tail-call recursion
Correct Answer: a) To collect all remaining arguments passed to a function into a true array
Explanation:
Rest parameters allow representing an indefinite number of arguments as an array.

11. How are default function parameters written in ES6?

a) function multiply(a, b = 1) { return a * b; }
b) function multiply(a, b default 1) { return a * b; }
c) function multiply(a, b) { b = b || 1; }
d) function multiply(a, b: 1) { return a * b; }
Correct Answer: a) function multiply(a, b = 1) { return a * b; }
Explanation:
ES6 introduced default parameter syntax, allowing parameters to be initialized with default values if no argument or undefined is passed.

12. Which of the following is an example of enhanced object literal syntax introduced in ES6?

a) Property value shorthand where `{ x, y }` is equivalent to `{ x: x, y: y }`
b) Method definition shorthand where `greet() {}` replaces `greet: function() {}`
c) Computed property names where object keys can be expressed dynamically using brackets `[propName]: value`
d) All of the above
Correct Answer: d) All of the above
Explanation:
ES6 enhanced object literals include property value shorthands, concise method syntax, and computed property names.

13. What is the syntax for defining a class in ES6?

a) class Person { constructor(name) { this.name = name; } }
b) def class Person { name: string; }
c) object Person { init(name) { this.name = name; } }
d) create class Person { constructor(name) { this.name = name; } }
Correct Answer: a) class Person { constructor(name) { this.name = name; } }
Explanation:
ES6 introduced the `class` keyword as syntactic sugar over JavaScript's prototype-based inheritance model.

14. Which keyword is used in ES6 classes to inherit from a parent class?

a) inherits
b) implements
c) extends
d) subclass
Correct Answer: c) extends
Explanation:
The `extends` keyword is used in class declarations to create a child class that inherits from a parent constructor.

15. What is the purpose of the `super` keyword inside a subclass constructor?

a) To call the parent class constructor and bind its prototype chain
b) To declare static variables
c) To export the class to external modules
d) To override private methods
Correct Answer: a) To call the parent class constructor and bind its prototype chain
Explanation:
When used in a constructor, `super()` calls the parent class constructor, which must be executed before accessing `this`.

16. What are the three possible states of a JavaScript Promise in ES6?

a) Pending, Fulfilled, Rejected
b) Active, Waiting, Completed
c) Loading, Success, Error
d) Open, Closed, Timeout
Correct Answer: a) Pending, Fulfilled, Rejected
Explanation:
A Promise exists in one of three states: pending (initial), fulfilled (success), or rejected (failure).

17. Which method is used to attach fulfillment and rejection handlers to a Promise?

a) promise.listen(resolve, reject)
b) promise.then(onFulfilled, onRejected)
c) promise.handle(success, error)
d) promise.await()
Correct Answer: b) promise.then(onFulfilled, onRejected)
Explanation:
The `then()` method returns a Promise and accepts callback functions for success and failure cases.

18. How do you handle errors or rejections in a Promise chain?

a) Using promise.catch(onRejected)
b) Using try-catch blocks synchronously around the promise creation
c) Using promise.fail()
d) Using error event listeners on window
Correct Answer: a) Using promise.catch(onRejected)
Explanation:
The `catch()` method handles rejections anywhere in a promise chain.

19. What does `Promise.all([p1, p2, p3])` return when all input promises are successfully fulfilled?

a) The result of the first fulfilled promise
b) A new promise resolved with an array containing the fulfillment values of all input promises in order
c) A boolean true value
d) An iterator object
Correct Answer: b) A new promise resolved with an array containing the fulfillment values of all input promises in order
Explanation:
Promise.all() waits for all input promises to fulfill, returning an array of their results.

20. How does `Promise.race([p1, p2, p3])` behave?

a) It resolves or rejects as soon as any one of the input promises settles (fulfills or rejects), with the value or reason from that promise.
b) It waits for all promises to finish and returns the slowest one.
c) It runs promises sequentially one after another.
d) It returns a sorted array of results.
Correct Answer: a) It resolves or rejects as soon as any one of the input promises settles (fulfills or rejects), with the value or reason from that promise.
Explanation:
Promise.race returns a promise that settles as soon as the first input promise settles.

21. What is the syntax for exporting a named function or variable from an ES6 module?

a) export function myFunc() {}
b) module.exports = { myFunc }
c) public function myFunc() {}
d) share myFunc;
Correct Answer: a) export function myFunc() {}
Explanation:
ES6 modules use the `export` keyword to publish functions, variables, or objects.

22. How do you import a default export from another module file named 'utils.js'?

a) import { default as helper } from './utils.js';
b) import helper from './utils.js';
c) const helper = require('./utils.js');
d) include helper from './utils.js';
Correct Answer: b) import helper from './utils.js';
Explanation:
Default exports can be imported using any identifier name directly without curly braces.

23. What is a JavaScript Symbol introduced in ES6?

a) A primitive data type whose instances are unique and immutable, often used as hidden object property keys
b) A visual icon rendered in the DOM
c) An alias for regular string identifiers
d) A cryptographic hashing function
Correct Answer: a) A primitive data type whose instances are unique and immutable, often used as hidden object property keys
Explanation:
Symbols are unique, immutable primitive values used primarily to serve as unique property keys avoiding name collisions.

24. What does the built-in `Map` object provide in ES6?

a) A key-value data structure where keys can be of any data type (including objects and functions)
b) An array method that transforms elements like map()
c) A geographic mapping coordinate viewer
d) A strict JSON schema validator
Correct Answer: a) A key-value data structure where keys can be of any data type (including objects and functions)
Explanation:
Unlike standard objects whose keys are limited to strings and symbols, `Map` allows keys of any type.

25. What is the primary characteristic of an ES6 `Set` object?

a) It stores unique values of any type, automatically discarding duplicate entries.
b) It stores key-value pairs sorted in alphabetical order.
c) It is a fixed-size immutable array.
d) It provides thread-safe concurrent storage.
Correct Answer: a) It stores unique values of any type, automatically discarding duplicate entries.
Explanation:
A `Set` stores unique values of any type, automatically ignoring duplicate entries.

26. What is a WeakMap in ES6?

a) A collection of key/value pairs whose keys must be objects and are weakly referenced, allowing garbage collection if no other references exist
b) A Map with low memory performance
c) A Map where values expire after a timeout
d) An object that stores weak passwords
Correct Answer: a) A collection of key/value pairs whose keys must be objects and are weakly referenced, allowing garbage collection if no other references exist
Explanation:
WeakMap keys are objects with weak references, allowing garbage collection when no other references remain.

27. What is a WeakSet in ES6?

a) A collection of garbage-collectable object values without strong references
b) A Set with only one allowed element
c) A boolean array wrapper
d) An iterable set of primitive strings
Correct Answer: a) A collection of garbage-collectable object values without strong references
Explanation:
WeakSet stores only objects weakly, allowing them to be garbage-collected when unreferenced.

28. What does `Array.from()` do in ES6?

a) Creates a new, shallow-copied Array instance from an array-like or iterable object
b) Converts an array into a comma-separated string
c) Subclasses the Array constructor
d) Mutates an existing array in place
Correct Answer: a) Creates a new, shallow-copied Array instance from an array-like or iterable object
Explanation:
Array.from() converts array-like objects or iterables into true JavaScript arrays.

29. What does `Array.of()` do?

a) Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments
b) Returns the type of array instance
c) Checks if a value is an array
d) Returns the length of an array
Correct Answer: a) Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments
Explanation:
Array.of() creates a new array instance from variable arguments, avoiding single-number sparse array issues.

30. What does the Array.prototype.find() method return?

a) The value of the first element in the array that satisfies the provided testing function
b) The index of the matching element
c) A new array of all matching elements
d) A boolean true or false
Correct Answer: a) The value of the first element in the array that satisfies the provided testing function
Explanation:
find() returns the first element satisfying the callback test, or undefined if no match is found.

31. What does the Array.prototype.findIndex() method return when no elements pass the testing function?

a) -1
b) null
c) undefined
d) 0
Correct Answer: a) -1
Explanation:
findIndex() returns the index of the first matching element, or -1 if none match.

32. Which new String methods were introduced in ES6 to check for substring inclusion?

a) includes(), startsWith(), and endsWith()
b) contains(), beginsWith(), and finishesWith()
c) has(), starts(), and ends()
d) search(), match(), and locate()
Correct Answer: a) includes(), startsWith(), and endsWith()
Explanation:
ES6 added convenient prototype methods on String to simplify substring verification.

33. What does `String.prototype.repeat(n)` do in ES6?

a) Constructs and returns a new string which contains the specified number of copies of the string on which it was called
b) Repeats execution of a callback function n times
c) Loops through string characters iteratively
d) Validates regular expression repetitions
Correct Answer: a) Constructs and returns a new string which contains the specified number of copies of the string on which it was called
Explanation:
The repeat() method returns a new string consisting of multiple concatenated copies.

34. What is Number.isInteger() used for in ES6?

a) To determine whether the passed value is an integer number
b) To round numbers down to the nearest integer
c) To convert strings into integer numbers
d) To check if a number is positive or negative
Correct Answer: a) To determine whether the passed value is an integer number
Explanation:
Number.isInteger() returns true if the argument is a number and an integer.

35. What does Number.isNaN() do differently from the global `isNaN()` function?

a) Number.isNaN() does not force type coercion of the argument, returning true only if the value is a number and its value is NaN.
b) Global isNaN() is stricter than Number.isNaN().
c) Number.isNaN() converts strings to numbers before checking.
d) There is no difference between them.
Correct Answer: a) Number.isNaN() does not force type coercion of the argument, returning true only if the value is a number and its value is NaN.
Explanation:
Global isNaN coerces non-number arguments first, whereas Number.isNaN does not coerce.

36. What does `Object.assign(target, ...sources)` do in ES6?

a) Copies all enumerable own properties from one or more source objects to a target object, returning the modified target object
b) Deep clones nested objects recursively
c) Freezes object properties to prevent modification
d) Compares two objects for reference equality
Correct Answer: a) Copies all enumerable own properties from one or more source objects to a target object, returning the modified target object
Explanation:
Object.assign() merges or shallow copies object properties.

37. What does `Object.is(value1, value2)` do compared to the strict equality operator (`===`)?

a) It behaves like `===` except it correctly treats `NaN` as equal to `NaN` and `+0` as not equal to `-0`.
b) It performs deep structural equality checks on nested objects.
c) It checks type coercion like the loose equality operator (`==`).
d) It is an alias for Object.assign().
Correct Answer: a) It behaves like `===` except it correctly treats `NaN` as equal to `NaN` and `+0` as not equal to `-0`.
Explanation:
Object.is provides SameValue comparison semantics for edge cases like NaN and signed zeros.

38. What is an ES6 generator function?

a) A function that can be paused and resumed using the `yield` keyword, returning an iterator object
b) A function that automatically generates random security tokens
c) A constructor function used to instantiate classes
d) An asynchronous worker thread initializer
Correct Answer: a) A function that can be paused and resumed using the `yield` keyword, returning an iterator object
Explanation:
Generator functions are declared with an asterisk and yield multiple values over time.

39. Which keyword is used inside a generator function to return a value and pause execution?

a) yield
b) await
c) pause
d) return
Correct Answer: a) yield
Explanation:
The `yield` keyword pauses generator execution and emits an iterator value.

40. What is an Iterator protocol in ES6?

a) A standard way for an object to produce a sequence of values, requiring a `next()` method that returns an object with `value` and `done` properties
b) A protocol for networking between server and client
c) A loop optimization algorithm in the V8 engine
d) A standard for asynchronous event streams
Correct Answer: a) A standard way for an object to produce a sequence of values, requiring a `next()` method that returns an object with `value` and `done` properties
Explanation:
The iterator protocol defines sequential traversal yielding `{ value, done }` objects.

41. How do you make a custom object iterable using the ES6 iteration protocol?

a) By implementing a method with the `Symbol.iterator` key that returns an iterator object
b) By adding an `iterable: true` property
c) By extending the Array class
d) By wrapping the object in JSON.stringify
Correct Answer: a) By implementing a method with the `Symbol.iterator` key that returns an iterator object
Explanation:
Implementing `[Symbol.iterator]()` allows custom objects to be traversed using `for...of` loops.

42. What is the purpose of the `for...of` loop introduced in ES6?

a) To iterate over iterable objects (like arrays, strings, maps, and sets) directly accessing their values
b) To iterate over enumerable object property keys
c) To loop through object properties asynchronously
d) To replace standard `while` loops for performance
Correct Answer: a) To iterate over iterable objects (like arrays, strings, maps, and sets) directly accessing their values
Explanation:
The `for...of` loop traverses values of any iterable collection directly.

43. What does `Reflect` API provide in ES6?

a) A built-in object that provides methods for intercepting JavaScript operations corresponding to proxy traps
b) A tool to inspect DOM node reflection
c) A compiler for translating ES6 to ES5
d) A debugging utility for tracking stack traces
Correct Answer: a) A built-in object that provides methods for intercepting JavaScript operations corresponding to proxy traps
Explanation:
The `Reflect` API provides static methods mirroring proxy operations.

44. What is a JavaScript `Proxy` in ES6?

a) An object used to define custom behavior for fundamental operations like property lookup, assignment, and function invocation
b) A network proxy server configuration utility
c) A mock testing stub
d) A wrapper for secure CORS requests
Correct Answer: a) An object used to define custom behavior for fundamental operations like property lookup, assignment, and function invocation
Explanation:
A `Proxy` wraps a target object and intercepts operations through custom handler traps.

45. What is tail call optimization (TCO) in ES6?

a) A feature where recursive functions that make a tail call do not grow the call stack, preventing stack overflow errors
b) An algorithm to sort arrays from tail to head
c) A method to optimize event listener cleanups
d) A garbage collection optimization for unused variables
Correct Answer: a) A feature where recursive functions that make a tail call do not grow the call stack, preventing stack overflow errors
Explanation:
TCO allows engine-level recycling of stack frames when a function's last action is a recursive call.

46. What does octal and binary literal syntax look like in ES6 numbers?

a) Binary uses `0b` or `0B`, and octal uses `0o` or `0O` prefixes
b) Binary uses `bin:` and octal uses `oct:`
c) Binary uses `b#` and octal uses `o#`
d) ES6 dropped support for binary and octal literals.
Correct Answer: a) Binary uses `0b` or `0B`, and octal uses `0o` or `0O` prefixes
Explanation:
ES6 introduced explicit literal prefixes: `0b`/`0B` for binary and `0o`/`0O` for octal.

47. What are tagged template literals in ES6?

a) A feature that allows parsing template literals with a custom function (tag) to manipulate the interpolation output
b) Templates containing HTML tags injected into the DOM
c) XML-tagged string literals
d) Templates with CSS class tags
Correct Answer: a) A feature that allows parsing template literals with a custom function (tag) to manipulate the interpolation output
Explanation:
Tagged templates let you parse string literals through a custom tag function.

48. In a tagged template function, what does the first argument (often named `strings`) contain?

a) An array of literal string strings split around the expression placeholders
b) The full combined interpolated string
c) An array of the evaluated expression values
d) The parsing options object
Correct Answer: a) An array of literal string strings split around the expression placeholders
Explanation:
The first parameter receives literal string chunks split by expression interpolations.

49. How do you define a static method inside an ES6 class?

a) Using the `static` keyword before the method name, e.g., `static info() {}`
b) Using the `classMethod` keyword
c) Defining it outside the class prototype
d) Static methods are not supported in ES6 classes.
Correct Answer: a) Using the `static` keyword before the method name, e.g., `static info() {}`
Explanation:
Static methods are called on the class itself rather than instances, using the `static` keyword.

50. Can ES6 class methods be generator functions?

a) Yes, by prefixing the method name with an asterisk `*`, e.g., `*generatorMethod() {}`
b) No, generators can only be standalone functions.
c) Only if defined as arrow functions.
d) Only inside static class declarations.
Correct Answer: a) Yes, by prefixing the method name with an asterisk `*`, e.g., `*generatorMethod() {}`
Explanation:
ES6 supports generator methods in classes and object literals using generator syntax.

51. What is the return value of `Math.trunc(4.9)` in ES6?

a) 4
b) 5
c) 4.9
d) 0
Correct Answer: a) 4
Explanation:
Math.trunc() removes fractional digits, returning the integer part without rounding.

52. What does `Math.sign(-5)` return in ES6?

a) -1
b) 1
c) 0
d) NaN
Correct Answer: a) -1
Explanation:
Math.sign() returns the sign of a number (-1, 0, or 1).

53. What is the output of `Number.EPSILON` in JavaScript?

a) The difference between 1 and the smallest floating point number greater than 1, useful for floating-point comparisons
b) Infinity
c) The maximum safe integer value
d) The mathematical constant e
Correct Answer: a) The difference between 1 and the smallest floating point number greater than 1, useful for floating-point comparisons
Explanation:
Number.EPSILON represents machine precision tolerance for floating-point calculations.

54. What does `Number.MAX_SAFE_INTEGER` represent?

a) The maximum integer that can be represented accurately without loss of precision ($2^{53} - 1$)
b) The maximum memory size of a number in bytes
c) Infinity
d) The largest 32-bit signed integer
Correct Answer: a) The maximum integer that can be represented accurately without loss of precision ($2^{53} - 1$)
Explanation:
Integers above MAX_SAFE_INTEGER cannot be guaranteed to be unique or accurate due to IEEE 754 precision limits.

55. What is the primary benefit of ES6 Modules over traditional script tags?

a) They provide strict mode by default, support isolated module scopes to prevent global namespace pollution, and enable explicit dependency imports/exports.
b) They execute twice as fast as normal scripts without parsing.
c) They allow running server-side SQL queries directly in the browser.
d) They eliminate the need for HTTP requests.
Correct Answer: a) They provide strict mode by default, support isolated module scopes to prevent global namespace pollution, and enable explicit dependency imports/exports.
Explanation:
ES6 modules bring native modular architecture with encapsulated scopes and explicit imports/exports.

56. What attribute must be added to a `` tag in HTML to load an ES6 module correctly?

a) type="module"
b) async="es6"
c) module="true"
d) target="es6"
Correct Answer: a) type="module"
Explanation:
Setting `type="module"` instructs the browser to parse script files as ES6 modules.

57. Are ES6 modules evaluated asynchronously or synchronously?

a) ES6 modules are parsed, loaded, and evaluated asynchronously (deferred by default).
b) They block HTML parsing completely.
c) They run inside web workers synchronously.
d) They execute before any HTML is parsed.
Correct Answer: a) ES6 modules are parsed, loaded, and evaluated asynchronously (deferred by default).
Explanation:
Module scripts are deferred by default, executing after HTML parsing completes.

58. Can an ES6 module have multiple named exports?

a) Yes, any number of named exports can be defined using the `export` keyword.
b) No, only one named export is permitted per file.
c) Only if combined with a default export.
d) Named exports are deprecated in favor of default exports.
Correct Answer: a) Yes, any number of named exports can be defined using the `export` keyword.
Explanation:
A single module file can export multiple named variables, functions, or classes.

59. How do you rename an exported item during import using ES6 module syntax?

a) import { originalName as newName } from './module.js';
b) import { originalName rename newName } from './module.js';
c) import { originalName: newName } from './module.js';
d) import newName = originalName from './module.js';
Correct Answer: a) import { originalName as newName } from './module.js';
Explanation:
The `as` keyword is used to alias imported or exported module bindings.

60. What does `import * as utilities from './utils.js'` do?

a) Imports all exported members of './utils.js' as properties of a single namespace object named 'utilities'
b) Imports only the default export
c) Imports all external network dependencies
d) Throws a syntax error if there are multiple exports
Correct Answer: a) Imports all exported members of './utils.js' as properties of a single namespace object named 'utilities'
Explanation:
Namespace imports bundle all named exports into a single namespace object container.

61. What happens if you reassign a `const` variable in ES6?

a) Throws a TypeError at runtime
b) Silently ignores the assignment
c) Treats it as a var declaration
d) Throws a SyntaxError at parse time
Correct Answer: a) Throws a TypeError at runtime
Explanation:
Reassigning a constant variable throws a TypeError in JavaScript.

62. What is the output of `typeof (class {})` in ES6?

a) "function"
b) "object"
c) "class"
d) "undefined"
Correct Answer: a) "function"
Explanation:
Classes in ES6 are syntactically based on prototype inheritance and evaluate to the type "function".

63. Can ES6 class constructors return a custom object?

a) Yes, if a constructor returns an object, that object will be returned as the instance of new.
b) No, constructors must always return undefined.
c) Only if returning a primitive string or number.
d) Throwing an error is required if returning objects.
Correct Answer: a) Yes, if a constructor returns an object, that object will be returned as the instance of new.
Explanation:
If a constructor explicitly returns an object, that object overrules the default `this` instance.

64. What is the role of `super.property` inside an ES6 subclass method?

a) To call methods or access properties defined on the parent class prototype
b) To access global window variables
c) To reference child class properties
d) To delete parent prototype properties
Correct Answer: a) To call methods or access properties defined on the parent class prototype
Explanation:
Using `super.methodName()` allows derived classes to invoke parent prototype methods.

65. Which method on Promise constructor creates a resolved promise immediately with a given value?

a) Promise.resolve(value)
b) Promise.success(value)
c) Promise.done(value)
d) Promise.fulfill(value)
Correct Answer: a) Promise.resolve(value)
Explanation:
Promise.resolve() returns a Promise object resolved with the given value.

66. Which method on Promise constructor creates a rejected promise immediately with a given reason?

a) Promise.reject(reason)
b) Promise.error(reason)
c) Promise.fail(reason)
d) Promise.throw(reason)
Correct Answer: a) Promise.reject(reason)
Explanation:
Promise.reject() returns a Promise object rejected with the specified reason.

67. What does `Promise.prototype.finally()` do in ES6 / ES2018 promises?

a) Schedules a callback to be called when the promise is settled (either fulfilled or rejected), useful for cleanup tasks.
b) Forces the promise to resolve successfully.
c) Terminates execution of pending promises.
d) Catches unhandled errors.
Correct Answer: a) Schedules a callback to be called when the promise is settled (either fulfilled or rejected), useful for cleanup tasks.
Explanation:
The finally() method runs regardless of whether the promise succeeded or failed.

68. What is the syntax for computed property names in ES6 object literals?

a) const obj = { ['key_' + 1]: 'value' };
b) const obj = { key(1): 'value' };
c) const obj = { dynamic key: 'value' };
d) Computed properties are not allowed in object literals.
Correct Answer: a) const obj = { ['key_' + 1]: 'value' };
Explanation:
Computed property names allow wrapping expressions in square brackets inside object literals.

69. How do you extract nested properties using object destructuring in ES6?

a) const { user: { address: { city } } } = data;
b) const { user.address.city } = data;
c) const { city } = data.user.address;
d) Nested property extraction is not supported.
Correct Answer: a) const { user: { address: { city } } } = data;
Explanation:
Object destructuring supports deep nesting by nesting property patterns inside assignments.

70. What happens when you destructure an undefined or null value in ES6?

a) Throws a TypeError
b) Assigns default values automatically
c) Returns an empty object
d) Fails silently with undefined variables
Correct Answer: a) Throws a TypeError
Explanation:
Attempting to destructure properties from `null` or `undefined` throws a TypeError.

71. Can rest parameters be placed anywhere in a function parameter list?

a) No, the rest parameter must be the last parameter in the function definition.
b) Yes, it can be placed at the beginning or middle.
c) Multiple rest parameters are allowed.
d) Rest parameters cannot be used with arrow functions.
Correct Answer: a) No, the rest parameter must be the last parameter in the function definition.
Explanation:
The rest parameter must always be the final parameter in a function definition.

72. What is the output of `[1, 2, 3].includes(2)` in ES6?

a) true
b) 1
c) 2
d) false
Correct Answer: a) true
Explanation:
Array.prototype.includes() returns true if the array contains the specified element.

73. How does `Array.prototype.includes()` handle `NaN` compared to `indexOf()`?

a) includes() correctly finds NaN, whereas indexOf() cannot find NaN because NaN !== NaN.
b) indexOf() finds NaN faster than includes().
c) Both methods fail to find NaN.
d) includes() throws a TypeError on NaN.
Correct Answer: a) includes() correctly finds NaN, whereas indexOf() cannot find NaN because NaN !== NaN.
Explanation:
includes() uses SameValueZero equality comparison, allowing it to locate NaN elements.

74. What does `Number.isSafeInteger(9007199254740992)` return?

a) false
b) true
c) undefined
d) TypeError
Correct Answer: a) false
Explanation:
9007199254740992 ($2^{53}$) is one greater than MAX_SAFE_INTEGER, exceeding safe integer precision.

75. What is the purpose of `String.prototype.codePointAt(pos)` in ES6?

a) Returns a non-negative integer that is the Unicode code point value at the given position, supporting surrogate pairs correctly.
b) Returns the ASCII character code.
c) Returns the cryptographic hash of a string.
d) Returns the string length.
Correct Answer: a) Returns a non-negative integer that is the Unicode code point value at the given position, supporting surrogate pairs correctly.
Explanation:
codePointAt() properly handles full Unicode characters outside the Basic Multilingual Plane.

76. What does `String.fromCodePoint()` do?

a) Returns a string created by using the specified sequence of code points
b) Returns the code point number for a letter
c) Encodes a string in base64
d) Parses HTML entities
Correct Answer: a) Returns a string created by using the specified sequence of code points
Explanation:
String.fromCodePoint() creates strings from Unicode code point numbers.

77. Can arrow functions be used as constructors with the `new` keyword?

a) No, arrow functions throw a TypeError if invoked with `new` because they lack a prototype property.
b) Yes, they create instances normally.
c) Only if they contain a constructor method.
d) Yes, but they inherit from Object by default.
Correct Answer: a) No, arrow functions throw a TypeError if invoked with `new` because they lack a prototype property.
Explanation:
Arrow functions lack a prototype and cannot be invoked as constructors with `new`.

78. What is the value of `this` inside an arrow function defined globally in browser JavaScript?

a) The global `window` object
b) undefined
c) null
d) The global document object
Correct Answer: a) The global `window` object
Explanation:
In the global execution context, lexical `this` of an arrow function points to the global window object.

79. What does the `Map.prototype.size` property return?

a) The number of key/value pairs in the Map
b) The total memory byte size
c) The maximum capacity
d) An array of keys
Correct Answer: a) The number of key/value pairs in the Map
Explanation:
The `size` property returns the count of key-value entries stored in a Map or Set.

80. How do you remove all elements from an ES6 `Map` or `Set`?

a) map.clear()
b) map.reset()
c) map.delete()
d) map.length = 0
Correct Answer: a) map.clear()
Explanation:
The `clear()` method removes all key-value entries from a Map or Set.

81. What does `Set.prototype.has(value)` return?

a) A boolean indicating whether an element with the specified value exists in the Set
b) The index of the value
c) The count of occurrences
d) An iterator object
Correct Answer: a) A boolean indicating whether an element with the specified value exists in the Set
Explanation:
The `has()` method checks for the existence of a value in a Set, returning true or false.

82. Can you use `for...in` to iterate over values of an ES6 `Set`?

a) No, `for...in` iterates over enumerable object property keys, whereas Sets are iterated using `for...of` or `.forEach()`.
b) Yes, it iterates through set elements in order.
c) Yes, but only in strict mode.
d) Sets do not support any iteration methods.
Correct Answer: a) No, `for...in` iterates over enumerable object property keys, whereas Sets are iterated using `for...of` or `.forEach()`.
Explanation:
Sets are iterable collections best traversed with `for...of` or `.forEach()`, not `for...in`.

83. What does `Reflect.has(obj, property)` do?

a) Works like the `in` operator, returning a boolean indicating whether the property exists on the object or its prototype chain
b) Deletes the property from the object
c) Returns the property descriptor
d) Checks if the object is frozen
Correct Answer: a) Works like the `in` operator, returning a boolean indicating whether the property exists on the object or its prototype chain
Explanation:
Reflect.has() mirrors property presence checking using the `in` operator.

84. What is the purpose of `Reflect.ownKeys(obj)`?

a) Returns an array of all own property keys (including strings and symbols) of the target object
b) Returns only inherited prototype keys
c) Returns string keys excluding symbols
d) Returns object values
Correct Answer: a) Returns an array of all own property keys (including strings and symbols) of the target object
Explanation:
Reflect.ownKeys() combines own string keys and symbol keys into a single array.

85. What happens when a Proxy trap returns a value inconsistent with the target object's non-configurable property (`invariant violation`)?

a) The JavaScript engine throws a TypeError.
b) The operation succeeds with a warning.
c) The proxy is automatically revoked.
d) Returns undefined.
Correct Answer: a) The JavaScript engine throws a TypeError.
Explanation:
Proxies enforce structural invariants; violating underlying configurations throws a TypeError.

86. How do you revoke a revocable Proxy created with `Proxy.revocable()`?

a) Calling the `revoke()` function returned alongside the proxy instance
b) Setting `proxy.revoked = true`
c) Deleting the target object
d) Proxies cannot be revoked.
Correct Answer: a) Calling the `revoke()` function returned alongside the proxy instance
Explanation:
Proxy.revocable() returns `{ proxy, revoke }`. Invoking `revoke()` disables the proxy.

87. What is the return value of `Reflect.getPrototypeOf(obj)`?

a) The prototype of the specified object (equivalent to Object.getPrototypeOf)
b) The constructor function reference
c) A boolean success flag
d) An array of parent classes
Correct Answer: a) The prototype of the specified object (equivalent to Object.getPrototypeOf)
Explanation:
Reflect.getPrototypeOf provides reflective access to an object's internal prototype linkage.

88. Can `Object.assign()` copy inherited properties or non-enumerable properties?

a) No, it only copies enumerable own properties of the source objects.
b) Yes, it copies the entire prototype chain.
c) Yes, if configured with a descriptor flag.
d) It only copies non-enumerable properties.
Correct Answer: a) No, it only copies enumerable own properties of the source objects.
Explanation:
Object.assign ignores inherited properties and non-enumerable properties.

89. What is the output of `[...'abc']` in ES6?

a) ['a', 'b', 'c']
b) "abc"
c) ['abc']
d) TypeError
Correct Answer: a) ['a', 'b', 'c']
Explanation:
Strings are iterables in ES6, so spreading a string expands each character into array elements.

90. How do default parameters interact with `undefined` values passed to a function?

a) Passing `undefined` triggers the default parameter value, whereas passing `null` or other falsy values does not.
b) Passing any falsy value triggers the default parameter.
c) Default parameters only trigger when arguments are omitted entirely.
d) Passing undefined throws an error.
Correct Answer: a) Passing `undefined` triggers the default parameter value, whereas passing `null` or other falsy values does not.
Explanation:
Default parameter evaluation specifically checks if the argument is strictly `undefined`.

91. What is a major advantage of using `const` for variable declarations in ES6 projects?

a) It communicates immutability of binding intent to other developers and helps engines optimize variable bindings.
b) It executes code twice as fast as var.
c) It automatically converts variables into global properties.
d) It prevents garbage collection.
Correct Answer: a) It communicates immutability of binding intent to other developers and helps engines optimize variable bindings.
Explanation:
Using `const` signals that the variable reference will not be reassigned, improving clarity.

92. How do ES6 arrow functions handle constructor invocation (`new fn()`)?

a) They cannot be used as constructors and throw a TypeError.
b) They initialize instances automatically.
c) They return an empty object.
d) They invoke the super constructor.
Correct Answer: a) They cannot be used as constructors and throw a TypeError.
Explanation:
Arrow functions lack a prototype property and throw a TypeError if called with `new`.
← Previous: JavaScript Error Handling MCQs for Developer Interviews & Certification
Next →: JavaScript Event Handling MCQs
NewLatest Python Operators MCQs

Latest Python Operators MCQs

Operators in Python are special symbols and keywords used to manipulate data, perform mathematical computations, make boolean comparisons, and control…

By MCQs Generator
NewPython Strings MCQs

Python Strings MCQs

In Python, a string (str) is an immutable sequence of Unicode characters used to represent text data. Defined using single,…

By MCQs Generator
NewJavaScript Closures MCQs

JavaScript Closures MCQs for Senior Developer Interviews

A closure in JavaScript is formed when an inner function retains access to the variables of its outer enclosing lexical…

By MCQs Generator