Mastering Advanced JavaScript: The Ultimate Self-Assessment Quiz — Questions & Answers

This quiz contains 5 questions. Below is a complete reference of all questions, answer choices, and correct answers. You can use this section to review after taking the interactive quiz above.

  1. Question 1: Question 1

    In JavaScript, what will be logged to the console when executing the following code? let foo = { bar: 1 }; Object.freeze(foo); foo.bar = 2; console.log(foo.bar);

    • A: 1
    • B: 2
    • C: undefined
    • D: null
    • E: ReferenceError
    Show correct answer

    Correct answer: A: 1

  2. Question 2: Question 2

    Which statement about closures in JavaScript is correct?

    • A: Closures can only access variables declared with let.
    • B: Closures allow a function to access variables from its parent scope even after the parent function has closed.
    • C: Closures create copies of variables from the outer function's scope.
    • D: Closures are destroyed immediately after the function executes.
    • E: Closures cannot access global variables.
    Show correct answer

    Correct answer: B: Closures allow a function to access variables from its parent scope even after the parent function has closed.

  3. Question 3: Question 3

    Given the following code, which value will be shown by alert? var a = 1; function f() { var a = 2; setTimeout(function() { alert(a); }, 0); } f();

    • A: 1
    • B: 2
    • C: undefined
    • D: It will throw an error
    • E: NaN
    Show correct answer

    Correct answer: B: 2

  4. Question 4: Question 4

    What is the result of the following expression in JavaScript? 0.1 + 0.2 === 0.3

    • A: true
    • B: false
    • C: undefined
    • D: 'true'
    • E: TypeError
    Show correct answer

    Correct answer: B: false

  5. Question 5: Question 5

    Which of the following will NOT create a shallow copy of an array named arr in JavaScript?

    • A: arr.slice()
    • B: [...arr]
    • C: Array.from(arr)
    • D: arr.concat()
    • E: arr.push()
    Show correct answer

    Correct answer: E: arr.push()