JavaScript Fundamentals: Scoping, Template Literals, and Arrow Functions Quiz

  1. Variable Hoisting and Scoping (var, let, const)
  2. Template Literals (using ${} for string interpolation)
  3. Arrow Functions and the this Keyword

This quiz is designed to help you understand JavaScript variables, template literals, and arrow functions through real-world scenarios!

Question 1.

What will the following code output? console.log(x); var x = 10;

  • A.

    10

  • B.

    undefined

  • C.

    ReferenceError

  • D.

    null

Question 2.

What happens when you declare a variable with let and access it before initialization?

  • A.

    Returns undefined

  • B.

    Throws a ReferenceError

  • C.

    Automatically assigns null

  • D.

    It works fine

Question 3.

Which of the following is a correct use of template literals?

  • A.

    My age is + age

  • B.

    My age is ${}

  • C.

    My age is ${age}

  • D.

    "My age is " + age

Question 4.

What will the following code output? const name = "Alice"; console.log(`Hello, ${name}!`);

  • A.

    Hello, Alice!

  • B.

    Hello, ${name}!

  • C.

    undefined

  • D.

    Error

Question 5.

What is the behavior of this inside an arrow function?

  • A.

    It refers to the global object

  • B.

    It creates a new this

  • C.

    It throws an error

  • D.

    It refers to the enclosing lexical scope

Question 6.

What will the following code output? const obj = { name: "Bob", greet: () => console.log(`Hello, ${this.name}`) }; obj.greet();

  • A.

    Hello, Bob

  • B.

    Error

  • C.

    Hello, undefined

  • D.

    Hello, null

Question 7.

What will the following code do? try { console.log(5 / 0); } catch (err) { console.log("Error"); }

  • A.

    Output Error

  • B.

    Throws a runtime error

  • C.

    Output Infinity

  • D.

    Error in syntax

Question 8.

Which block is always executed in a try-catch-finally statement?

  • A.

    try

  • B.

    catch

  • C.

    finally

  • D.

    None of the above

Question 9.

What will the following code output? let x = 10; { let x = 20; console.log(x); } console.log(x);

  • A.

    20, 20

  • B.

    20, 10

  • C.

    10, 20

  • D.

    Error

Question 10.

What will happen if you reassign a const variable? const age = 25; age = 30; console.log(age);

  • A.

    Outputs 30

  • B.

    Outputs 25

  • C.

    Throws a TypeError

  • D.

    Outputs undefined