JavaScript let, const & var Quiz

This JavaScript quiz checks the three ways to declare a variable. You will predict output involving block scope, reassignment and redeclaration, and see why modern code uses const and let instead of var.

Easy 10 questions ~5 minutes Pass at 80% Node.js 22

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

let x = 1;
{
  let x = 2;
}
console.log(x);
Show the answer

B. 1 The inner let x is a new variable that only lives inside the braces. Outside the block, x is still the outer one, which holds 1.

What this quiz covers

  • Block scope with let and const
  • Function scope with var
  • Why const stops reassignment but not changes to an object
  • Redeclaring a variable with var vs let
  • var vs let in a for loop

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.