Last active
June 30, 2019 18:21
-
-
Save DenisCangemi/baf223d9cc3a743b39b4a4dfb25c002d to your computer and use it in GitHub Desktop.
Example of var keyword visibility
This file contains 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
// Example of var keyword visibility | |
if ( true ) { | |
var x = 20; | |
} | |
function set() { | |
var x = 50; | |
// Write the values in the console | |
console.log(x); // Result : 50 | |
var y = 30; | |
} | |
// Call the set() function | |
set(); | |
// Write the values in the console | |
console.log(x); // Result : 20 | |
console.log(y); // Result : Error not defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment