Skip to content

Instantly share code, notes, and snippets.

@Bambina-zz
Created July 19, 2015 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bambina-zz/d640281af4c5701884ee to your computer and use it in GitHub Desktop.
Save Bambina-zz/d640281af4c5701884ee to your computer and use it in GitHub Desktop.
js block scope (ES6)
(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