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.
Loading...
Related Quiz
- Given a scenario where you need to flatten a deeply nested array, how would you implement this using recursion in ES6?
- In what ways can destructuring assignment be utilized in function parameters?
- An unhandled promise rejection can be caught globally using process.on('________', handler).
- What kind of exports are more conducive to effective tree shaking?
- How can enhanced object literals in ES6 improve the process of creating objects that inherit from another object?