Created
November 27, 2018 04:48
-
-
Save ketanghumatkar/d0c88d01c0020120a1530b48aa5281db to your computer and use it in GitHub Desktop.
javascript_hoisting_examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Program 1 | |
function foo(){ | |
function bar() { | |
return 3; | |
} | |
return bar(); | |
function bar() { | |
return 8; | |
} | |
} | |
alert(foo()); | |
// Program 2 | |
alert(foo()); | |
function foo() { | |
var bar = function() { | |
return 3; | |
}; | |
return bar(); | |
var bar = function() { | |
return 8; | |
}; | |
} | |
// Program 3 | |
function foo() { | |
return bar(); | |
var bar = function() { | |
return 3; | |
}; | |
var bar = function() { | |
return 8; | |
}; | |
} | |
alert(foo()); | |
// Program 4 | |
function foo() { | |
var bar = function() { | |
return 3; | |
}; | |
return bar(); | |
var bar = function() { | |
return 8; | |
}; | |
} | |
alert(foo()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment