What is JavaScript Hoisting?
Hoisting in JavaScript is a behavior in which a function or a variable can be used before declaration.
// using test before declaring
console.log(test); // undefined
var test;
The above program works and the output will be undefined. The above program behaves as
// using test before declaring
var test;
console.log(test); // undefined
Since the variable test is only declared and has no value, undefined value is assigned to it.
0 Comments