JavaScript ES6+ Advanced Concepts Challenge Quiz

This quiz assesses your mastery of advanced JavaScript ES6+ features, including variable declarations, modern syntax, destructuring, modules, and classes. Test your deep understanding of nuanced language behaviors and subtle pitfalls.

  1. Block Scope Variable Behavior

    What will be logged by the following code snippet: 'let a = 5; if (true) { let a = 10; } console.log(a);'?

    1. 5
    2. 10
    3. undefined
    4. null
    5. ReferenceError
  2. Const Assignment Error

    What is the result of executing the following code: 'const obj = {}; obj = {a:1};'?

    1. The code throws a ReferenceError.
    2. Nothing happens; code runs silently.
    3. The code throws a TypeError.
    4. The object obj is reassigned successfully.
    5. It logs 'undefined'.
  3. Template Literals and Multiline Strings

    Which statement accurately describes template literals in JavaScript?

    1. They automatically escape special characters like and .
    2. They require double quotes for multi-line support.
    3. They only allow single-line strings.
    4. They preserve line breaks and allow embedded expressions using ${}.
    5. They do not support variable interpolation.
  4. Array Destructuring with Skipped Elements

    Given 'const arr = [1, 2, 3, 4];' what is the value of 'b' after '[, b, ,] = arr;'?

    1. 3
    2. 2
    3. 1
    4. undefined
    5. null
  5. Object Destructuring and Default Values

    Given 'const {a, b = 7} = {a: 3};', what is the value of 'b'?

    1. undefined
    2. 3
    3. 7
    4. null
    5. NaN
  6. Spread Operator in Function Calls

    Which result is produced by the following code: 'function sum(x, y, z) { return x + y + z; } const nums = [1, 2, 3]; sum(...nums);'?

    1. undefined
    2. 123
    3. Error: Too many arguments
    4. [1,2,3]
    5. 6
  7. Rest Parameters vs. Arguments Object

    Which statement is true about rest parameters in ES6 functions?

    1. Rest parameters are always empty if no argument is provided.
    2. Rest parameters are accessed with 'arguments' inside the function.
    3. Rest parameters transform all arguments into a single string.
    4. Rest parameters are true arrays, unlike the arguments object.
    5. Rest parameters include arguments passed before the ...rest parameter.
  8. Named vs Default Exports

    Considering the module export syntax, which import statement correctly imports the default export from a module named 'library.js'?

    1. import myExport from './library.js';
    2. import default from './library.js';
    3. import { myExport } from './library.js';
    4. import { default } from './library.js';
    5. import * as myExport from './library.js';
  9. Re-exporting Named Exports

    Which syntax re-exports a named export 'foo' from './module.js' without importing it locally?

    1. export * as foo from './module.js';
    2. export * from './module.js' as foo;
    3. export { foo } from './module.js';
    4. export foo from './module.js';
    5. export foo as './module.js';
  10. Class Field Declaration

    In JavaScript ES6, which syntax correctly defines an instance field 'count' initialized to 0 inside a class?

    1. let count = 0;
    2. this.count = 0; outside constructor
    3. var count = 0;
    4. count = 0;
    5. public count = 0;
  11. Method Binding in Classes

    Which approach is necessary to ensure a class method retains the correct 'this' context when used as a callback?

    1. Bind the method to 'this' in the constructor using '.bind(this)'.
    2. No action needed; methods are always bound.
    3. Declare the method as a static method only.
    4. Prefix the method with 'auto' keyword.
    5. Use an arrow function in the callback call only.
  12. Destructuring and Aliasing

    Given 'const obj = { x: 1, y: 2 };' which syntax assigns the value of 'x' to a variable 'z'?

    1. const z = obj[y];
    2. const { z: x } = obj;
    3. const { z } = obj;
    4. const z = obj.x;
    5. const { x: z } = obj;
  13. Shallow Copy with Spread Operator

    Given 'const arr1 = [1, [2, 3]]; const arr2 = [...arr1]; arr2[1][0] = 42;', what is the value of 'arr1[1][0]' after execution?

    1. 42
    2. null
    3. 2
    4. [42, 3]
    5. undefined
  14. Immutability and Const

    Which statement is true about objects declared with const?

    1. Their reference cannot be reassigned but their contents can be mutated.
    2. const prevents both reassignment and mutation.
    3. They are deeply frozen and immutable.
    4. Their properties cannot be changed but child objects can be.
    5. They become read-only arrays.
  15. Default Parameters and Undefined

    For the function 'function add(a = 2, b = 3) { return a + b; }', what does 'add(undefined, 4)' return?

    1. 6
    2. 4
    3. 5
    4. 23
    5. NaN