1. Which symbol is used to define a template literal in ES6?
A) Double quotes (" ")
B) Single quotes (' ')
C) Backticks (` `)
D) Curly braces { }
Show Explanation
2. What is the purpose of default parameters in JavaScript functions?
A) To set an initial value if no argument is passed
B) To prevent a function from being called without arguments
C) To make parameters constant
D) To enable overloading of functions
Show Explanation
3. Which ES6 feature allows extracting values from an object into separate variables?
A) Spread operator
B) Destructuring assignment
C) Default parameters
D) Arrow functions
Show Explanation
4. Which statement is true regarding let and const in ES6?
A) They are both global-scoped
B) They are the same as var
C) They are block-scoped
D) Only let is block-scoped
Show Explanation
5. Which feature of arrow functions differentiates them from regular functions?
A) They allow overloading
B) They are block-scoped
C) They lexically bind 'this'
D) They cannot be used as callbacks
Show Explanation
6. Which syntax is correct for embedding a variable in a template literal?
A) `Hello, ${name}!`
B) 'Hello, $name!'
C) 'Hello, ${name}'
D) `Hello, +name+!`
Show Explanation
7. What is the purpose of the spread operator in JavaScript?
A) To create new functions
B) To expand elements from an array or object
C) To declare variables
D) To destructure objects
Show Explanation
8. Which statement is true about variables declared with const?
A) They cannot be reassigned
B) They are mutable
C) They are function-scoped
D) They cannot be used with objects
Show Explanation
9. What does the rest parameter (...) do in a function?
A) It collects all remaining arguments into an array
B) It spreads elements into separate arguments
C) It makes a function synchronous
D) It changes the function context
Show Explanation
10. Which syntax correctly uses destructuring to assign values from an object?
A) var {a, b} = c;
B) const {a, b} = c;
C) let {a; b} = c;
D) const {a b} = c;
Show Explanation
11. How do template literals improve handling multi-line strings in JavaScript?
A) They require escaping for line breaks
B) They limit to single-line strings
C) They allow multi-line strings without concatenation
D) They use double quotes for line breaks
Show Explanation
12. Which syntax uses array destructuring to assign variables?
A) const [a, b] = array;
B) const a, b = array[];
C) let [a: b] = array;
D) var (a, b) = array;
Show Explanation
13. What value is assigned to the parameter 'x' in function test(x=5) if no argument is passed?
A) 0
B) 5
C) undefined
D) null
Show Explanation
14. Which of the following is a use of the rest operator (...)?
A) To collect multiple arguments in an array
B) To break arrays into individual elements
C) To declare constant values
D) To duplicate an array
Show Explanation
15. How does 'this' behave in arrow functions?
A) 'this' is always the global object
B) 'this' is undefined in arrow functions
C) 'this' can be explicitly set with 'call'
D) 'this' is lexically inherited from the enclosing scope
Show Explanation
16. What does the spread operator (...) allow when used with arrays?
A) To create a copy without elements
B) To merge arrays or add elements in place
C) To restrict array length
D) To prevent re-assignment
Show Explanation
17. How do template literals allow embedding expressions within strings?
A) Using double quotes with + operator
B) Using ${expression} syntax within backticks
C) Using single quotes with % syntax
D) By concatenating strings manually
Show Explanation
18. Where are let and const variables accessible?
A) Only within the block where they are defined
B) Globally throughout the code
C) Only at the function level
D) Only in the module scope
Show Explanation
19. Why might arrow functions be unsuitable for methods requiring a dynamic 'this' reference?
A) Because they inherit 'this' from their lexical scope
B) Because they are always anonymous
C) Because they can't return objects
D) Because they can only handle one parameter
Show Explanation
20. How can destructuring with rest syntax be used to collect remaining elements in an array?
A) const {...rest} = array;
B) const [a, ...rest] = array;
C) const [...rest, a] = array;
D) const [rest...] = array;
Show Explanation