chessboard using javascript

Hoisting is a JavaScript process to move the variable declaration at the top of the code, regardless of where it is defined. This is the reason in JavaScript that why we can use a variable before it has been declared.

name='pixxstudios';

console.log(name); // outputs pixxstudios

var name;

Variable Hoisting
In case of variable hoisting all the variable declarations are moved to the top of the code. If the variables are declared inside a function then they will move to the top of the function else if they are declared outside the function then they will move to the top of the script.

Remember that only variable DECLARATION are hoisted and INITIALIZATION are not hoisted. For example.

var i=10;
var j=20;
console.log(i+ " "+j);

// outputs 10 20

but this code will give different output

var i=10;
console.log(i+ " "+j);
var j=20;

// outputs 10 undefined

The above code is equivalent of

var i=10;
var j;
console.log(i+ " "+j);
j=20;

// outputs 10 undefined

Related Posts