Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Created October 24, 2016 19:53
Show Gist options
  • Save KinoAR/2d0b6ecf30938df55ad7789633d258db to your computer and use it in GitHub Desktop.
Save KinoAR/2d0b6ecf30938df55ad7789633d258db to your computer and use it in GitHub Desktop.
//=============================================================================
// Block Scoped Variables
//=============================================================================
//Variable Types
//var
//let
//ES5
function blockScope1() {
//Not considered a block scope for var
{
var a = 1;
}
function blockScope() {
var b = 0;
console.log("Block Scope 1: " + b); //Block Scope 1: 0
}
blockScope2();
console.log("Block Scope 1 :" + a); //Block Scope 1: 1
console.log("Block Scope 1: " + b); //b is not defined
}
blockScope1();
//ES6
function blockScope2() {
{
let a = 0;
console.log(`Block Scope 2 : ${a}`); //Block Scope 2 : 0
}
console.log(`Block Scope 2 : ${a}`);//a is not defined
}
blockScope2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment