JavaScript MCQs – ES6+ Features and Functional Programming

JavaScript MCQs – ES6+ Features and Functional Programming is a critical topic for interviews as it covers modern JavaScript advancements. Understanding concepts like let, const, arrow functions, promises, destructuring, and functional programming methods (map, reduce, filter) is essential. These features make code more efficient and readable. Practicing MCQs on these topics strengthens your knowledge and helps you prepare for advanced coding challenges in interviews.

1.) What does the let keyword do in ES6?

A) Declares a variable globally
B) Declares a variable with block scope
C) Declares a constant variable
D) Declares a variable with function scope

Answer: Option B

Explanation: The let keyword declares variables with block scope, meaning they are limited to the block in which they are defined.

2.) Which feature allows default values in functions?

A) Arrow functions
B) Rest parameters
C) Default parameters
D) Spread operator

Answer: Option C

Explanation: Default parameters in ES6 allow assigning default values to function arguments.

3.) What does the spread operator (…) do?

A) Merges arrays into objects
B) Splits arrays into individual elements
C) Expands iterable elements into individual values
D) Declares a rest parameter

Answer: Option C

Explanation: The spread operator expands iterable elements, such as arrays or objects, into individual elements or key-value pairs.

4.) How can you make a function return a promise in ES6?

A) By adding async before the function name
B) By using await inside the function
C) By calling .then() inside the function
D) By wrapping the return value in Promise.resolve()

Answer: Option A

Explanation: Adding the async keyword makes a function return a promise automatically.

5.) What does the const keyword do?

A) Declares a constant variable with global scope
B) Declares a variable that cannot be reassigned
C) Declares a variable with block scope
D) Both B and C

Answer: Option D

Explanation: The const keyword declares variables with block scope and prevents reassignment.

6.) Which method is used to create a shallow copy of an array in ES6?

A) Array.copy()
B) Array.clone()
C) […array]
D) Array.prototype.copy()

Answer: Option C

Explanation: The spread operator creates a shallow copy of an array by spreading its elements into a new array.

7.) What does the Promise constructor accept?

A) A string argument
B) A callback function with resolve and reject parameters
C) An array of values
D) Another promise

Answer: Option B

Explanation: The Promise constructor accepts a function that takes resolve and reject as arguments.

8.) What is the use of arrow functions in ES6?

A) Declares functions with a simpler syntax
B) Declares functions with lexical this binding
C) Supports this context binding
D) All of the above

Answer: Option D

Explanation: Arrow functions simplify syntax and use lexical scoping for the this keyword.

9.) Which symbol is used to create private class fields in ES6+?

A) _
B) #
C) private keyword
D) @

Answer: Option B

Explanation: Private fields in ES6+ classes are created using the # symbol, making them inaccessible outside the class.

10.) What does the map() method do in functional programming?

A) Filters elements based on a condition
B) Transforms each array element and returns a new array
C) Mutates the original array
D) Sorts the array

Answer: Option B

Explanation: map() applies a function to each element of an array, returning a new array with transformed values.

Leave a Reply

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