What is hoisting in JavaScript? Explain with an example.
Hoisting is the default behavior of moving all the declarations at the top of the scope before code execution. In JavaScript, all variable which are declared with ‘var’ and functions are moved on top of the scope.But variable declared with let, const and functions expression are won’t.
var a;console.log(a); //print undefined, beacuse of hoisting.
a=5;console.log(a); //print 5.
let b;console.log(b); //reference error, beacuse of hoisting.