How does hoisting behavior differ between variables declared with let/const and those declared with var?

  • Variables declared with var are hoisted to the top of their scope, while let/const variables are hoisted but not initialized.
  • Variables declared with let/const are hoisted to the top of their scope, while var variables are hoisted but not initialized.
  • Variables declared with let/const are not hoisted, while var variables are hoisted and initialized with undefined.
  • Variables declared with var are not hoisted, while let/const variables are hoisted and initialized with undefined.
In JavaScript, variables declared with var are hoisted and initialized with undefined at the top of their scope, while let and const are hoisted but not initialized. Accessing a let/const variable before its declaration results in a ReferenceError.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *