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.


Hoisting in JavaScript is a method where a function or variable may be utilized prior to declaration.

1. Variable hoisting

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

2. Function hoisting

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

BY Best Interview Question ON 24 Aug 2022