JavaScript MCQs – ES6+ Features and Functional Programming

11.) What is destructuring in ES6?

A) Breaking arrays or objects into smaller parts
B) Modifying array elements
C) Concatenating arrays
D) Copying objects

Answer: Option A

Explanation: Destructuring allows extracting values from arrays or objects into separate variables.

12.) How does Object.entries() work in ES6?

A) Converts an object into a string
B) Returns an array of key-value pairs from an object
C) Merges two objects
D) Creates an object clone

Answer: Option B

Explanation: Object.entries() returns an array of [key, value] pairs from an object’s own enumerable properties.

13.) What is the difference between == and === in ES6?

A) No difference
B) == checks type and value; === checks only value
C) == checks only value; === checks type and value
D) Both perform type coercion

Answer: Option C

Explanation: == checks for value equality with type coercion, while === checks for both type and value equality.

14.) What does the filter() method do?

A) Removes duplicates from an array
B) Filters elements based on a condition
C) Transforms array elements
D) Mutates the original array

Answer: Option B

Explanation: filter() creates a new array with elements that meet a specified condition.

15.) What is the purpose of reduce() in JavaScript?

A) optioReduces array size1
B) Executes a reducer function on each element, resulting in a single output
C) Concatenates arrays
D) Filters elements

Answer: Option B

Explanation: reduce() accumulates a result by applying a reducer function to each array element.

16.) What does Object.assign() do?

A) Copies values from one object to another
B) Creates an object reference
C) Merges two arrays
D) Declares an object

Answer: Option A

Explanation: Object.assign() copies enumerable properties from one or more source objects to a target object.

17.) Which new feature was introduced in ES6 for iteration?

A) forEach
B) for…of
C) while
D) do…while

Answer: Option B

Explanation: The for…of loop allows iteration over iterable objects like arrays and strings.

18.) Which feature allows you to create computed property names in objects?

A) Template literals
B) Arrow functions
C) Square brackets ([])
D) Object.assign()

Answer: Option C

Explanation: Square brackets allow defining computed property names in objects, such as { [key]: value }.

19.) What does the rest parameter (…) do?

A) Expands arrays into individual elements
B) Condenses multiple arguments into an array
C) Creates an object
D) Declares optional arguments

Answer: Option B

Explanation: Rest parameters collect all remaining arguments into an array.

20.) What does the includes() method do in ES6?

A) Checks if an array contains a specified value
B) Checks if a string contains a substring
C) Works on both arrays and strings
D) All of the above

Answer: Option D

Explanation: The includes() method determines whether a given value exists in an array or substring in a string, returning true or false.

Leave a Reply

Your email address will not be published. Required fields are marked *