Variable & Function hoisting in javascript
Hoisting is JavaScript's default behavior of moving declarations to the top of the current scope.
Hoisting can be applied to variable declarations and to function declarations. As a result of this, JavaScript functions & variables can be called before they are declared.
For example : -
1. variable Hoisting :
Hoisting can be applied to variable declarations and to function declarations. As a result of this, JavaScript functions & variables can be called before they are declared.
For example : -
1. variable Hoisting :
x = 8;
console.log(x); // prints 8
var x;
2. Function Hositing : -
displayName();
function displayName () {
console.log("I am rroxy");
}
* Function Hoisting applies to only functions not functions expressions, e.g : -
displayName(); // undefined var displayName = function () {console.log("I am rroxy");
}
Comments
Post a Comment