Optimistic human 🧍 and trying hard not to procrastinate things!!!😜 Passionate about Web Development and have a keen interest in learning new technologies.
Yep missed that one. That depends on the declaration. If that's inside particular block, it'll not get hoisted globally and if not, Let or const will be hoisted globally but due to temporal dead zone we can't access those until initialization.
"Let and const are hoisted in block scope whereas var is hoisted in global scope." -> Whenever we try to re declare a same variable using var inside a specific block, variable will get updated and that's not the same case with let because it is block scope so it will not be available outside the scope.
Example:
let greeting = "Hello";
if (true) {
let greeting = "Hi";
console.log(greeting); // "Hi"
}
console.log(greeting); // "Hello"
var greeting = "Hi";
if (true) {
var greeting= "Hello!";
console.log(greeting); // "Hello!"
}
console.log(greeting); // "Hello"
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yep missed that one. That depends on the declaration. If that's inside particular block, it'll not get hoisted globally and if not,
Let
orconst
will be hoisted globally but due to temporal dead zone we can't access those until initialization."Let and const are hoisted in block scope whereas var is hoisted in global scope." -> Whenever we try to re declare a same variable using
var
inside a specific block, variable will get updated and that's not the same case withlet
because it is block scope so it will not be available outside the scope.Example: