LearnFrenzy
Sign in Take a free test

Variables: var, let and const · Exercise 1 of 4

Variables: var, let and const var, let and const MCQ

  • 15 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript variables: function and block scope, hoisting, the temporal dead zone, redeclaration, const objects, Object.freeze and loop bindings. Pick an option to check your answer instantly.

Question 1 Easy

A variable is declared with var inside an if block in a function. Where can it be used?

A Only inside the if block
B Anywhere in the enclosing function
C Only after the if block
D Anywhere in the program
Question page & discussion
Question 2 Easy

What is the scope of variables declared with let and const?

A The nearest enclosing block { }
B The whole function
C The whole file
D Only the line where they are declared
Question page & discussion
Question 3 Easy

Which keyword allows the same variable to be declared twice in the same scope without an error?

A var
B let
C const
D let and const, but not var
Question page & discussion
Question 4 Medium

What exactly does const guarantee for const team = ["Asha", "Ravi"];?

A The array can never change
B team can be reassigned but not mutated
C The array is copied every time it is used
D team will always refer to the same array, but the array's elements can change
Question page & discussion
Question 5 Medium

What is the temporal dead zone (TDZ)?

A The time after a variable goes out of scope
B The time between the start of a block and the line where a let/const variable is declared, during which accessing it throws a ReferenceError
C The delay before setTimeout runs its callback
D The part of a loop where var variables are undefined
Question page & discussion
Question 6 Medium

Which statement about hoisting is correct?

A Only var is hoisted; let and const are not hoisted at all
B var, let and const are all initialised to undefined
C var is hoisted and initialised to undefined; let and const are hoisted but not initialised
D Hoisting physically moves code to the top of the file
Question page & discussion
Question 7 Hard

In a classic browser script (not a module), which top-level declaration creates a property on window?

A var appName = "LF";
B let appName = "LF";
C const appName = "LF";
D class AppName {}
Question page & discussion
Question 8 Easy

Which declaration is a SyntaxError when written without a value, e.g. ___ total;?

A const
B let
C var
D All three
Question page & discussion
Question 9 Hard

const cfg = Object.freeze({ db: { host: "local" } }); Which change still takes effect?

A cfg.db = {}
B cfg.port = 5432
C cfg.db.host = "remote"
D delete cfg.db
Question page & discussion
Question 10 Easy

Which declaration style do modern style guides recommend?

A var everywhere for compatibility
B const by default, let when the variable is reassigned, no var
C let everywhere
D const only for numbers
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links