/*------------Variable Declaration--------*/
function test() {
console.log(x)
}
test();
var a;
var x = 5;
let y = 'hello';
/* below how the code executes line by line */
// 1. First check declarations and its go to top var x;
// 2. And along with that function declarations done
// 3. Finally initialization and function call happens as line by line
/*------------Function Declaration--------*/
test1();
x();
function test1() { // named function will do hoisting
console.log('Hello');
}
var x = function() { //anonymous function or named function, it wont hoist
console.log('Hi');
}
//How it works
/* var x;
function test1() {
console.log('Hello');
}
test1();
x();
x = function() {
console.log('Hi');
}*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.