index.html
<!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>
jsbin.vahifug.js
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');