What is hoisting ??
a variable can be used before it has been declared because it stores in memory
for example
π function
b();
function b(){
console.log('foo');
}
// "foo"
// β
thanks to hoisting, function has stored in memory before declaring
βΌ But arrow function isn't like that
arrFn();
const arrFn = () => {
console.log('arrow!!');
}
// π₯ Uncaught ReferenceError: Cannot access 'arrFn' before initialization
π variable
console.log(b)
var b = 10;
// "undefined"
// β
default initialization of the var is undefined.
// β initial value = undefined
the case of const and let
console.log(NAME) // π₯ Throws ReferenceError exception as the variable value is uninitialized
const NAME = 'kaziu'
console.log(count) // π₯ Throws ReferenceError exception as the variable value is uninitialized
let count = 2
Top comments (0)