February 2018
Intermediate to advanced
298 pages
8h 22m
English
Variables that are declared using the let keyword are called block-scoped variables. Block-scoped variables behave the same way as function-scoped variables when declared outside a function, that is, they are accessible globally. But when block-scoped variables are declared inside a block, they are accessible inside the block that they are defined in (and also any sub-blocks) but not outside the block:
let a = 12; // accessible everywhere function myFunction() { console.log(a); // alerts 12 let b = 13; if(true) { let c = 14; // this is NOT accessible throughout the function! alert(b); // alerts 13 } alert(c); // alerts undefined } myFunction(); alert(b); // alerts undefined
Study the code carefully. This ...
Read now
Unlock full access