Created
July 19, 2015 12:15
-
-
Save Bambina-zz/d640281af4c5701884ee to your computer and use it in GitHub Desktop.
js block scope (ES6)
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
(function x(){ | |
var local = "local"; | |
if(true){ | |
console.log(local); //=>local | |
let block_scope = "block_scope"; //変数定義にletを使うと、定義したブロック内でのみ参照できるようになる。 | |
console.log(block_scope); //=>block_scope | |
} | |
console.log(block_scope); //=>block_scope is not defined エラーになる。 | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment