1. Home
  2. >
  3. What's the output?

What's the output?
rahoolbenji rahoolbenji

  • A: Lydia and undefined
  • B: Lydia and ReferenceError
  • C: ReferenceError and 21
  • D: undefined and ReferenceError

Answer: D 

Within the function, we first declare the name variable with the var keyword. This means that the variable gets hoisted.

Variables with the let keyword (and const) are hoisted, but unlike var, don't get initialized. They are not accessible before the line we declare (initialize) them. This is called the "temporal dead zone". When we try to access the variables before they are declared, JavaScript throws a ReferenceError.


# javascript# hoisting
function sayHi() {
  var name = 'Lydia';
  let age = 21;



# javascript# hoisting