Created
February 10, 2018 16:56
-
-
Save shreshthmohan/3e534337c9ed35ea48aad4a7b70b0554 to your computer and use it in GitHub Desktop.
ES6 - let - block scoping // source http://jsbin.com/vahifug
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>ES6 - let - block scoping</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const a = 6; | |
const b = 7; | |
if (a < b ) { | |
let c = 8; | |
console.log('c from inside the if block: ', c); | |
} | |
try { | |
console.log('c from outside the if block: ') | |
console.log(c); | |
} catch(err) { | |
console.log(err); | |
} | |
console.log('See that? This is block scoping. The variable c is available only inside the block it\'s declared in'); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
const a = 6; | |
const b = 7; | |
if (a < b ) { | |
let c = 8; | |
console.log('c from inside the if block: ', c); | |
} | |
try { | |
console.log('c from outside the if block: ') | |
console.log(c); | |
} catch(err) { | |
console.log(err); | |
} | |
console.log('See that? This is block scoping. The variable c is available only inside the block it\'s declared in'); | |
</script></body> | |
</html> |
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
const a = 6; | |
const b = 7; | |
if (a < b ) { | |
let c = 8; | |
console.log('c from inside the if block: ', c); | |
} | |
try { | |
console.log('c from outside the if block: ') | |
console.log(c); | |
} catch(err) { | |
console.log(err); | |
} | |
console.log('See that? This is block scoping. The variable c is available only inside the block it\'s declared in'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment