1.

What is JavaScript Hoisting?

Answer»

A JavaScript default behavior that moves the declaration of variables and functions at the top of the current SCOPE is CALLED JavaScript HOSTING. You can USE hosting for declaration, not for initialization.

Example

1. Variable hoisting

console.log(x); // UNDEFINED
var x = 1;

2. Function hoisting

let x = 20, y = 10;
let result = add(x,y);
console.log(result);
function add(a, b) {
     return a + b;
}



Discussion

No Comment Found