// 2.B.1.4
// const and let, from ECMAScript 6, should likewise be at the top of their scope (block).
// Bad
function foo() {
let foo,
bar;
if ( condition ) {
bar = "";
// statements
}
}
// Good
function foo() {
let foo;
if ( condition ) {
let bar = "";
// statements
}
}
Am i getting this wrong. Aren't we supposed to initialize the variables at the beginning of the scope. But here "bar" is declared inside "if", JavaScript doesn't have scope block right. So is this correct. Can someone explain this.
Am i getting this wrong. Aren't we supposed to initialize the variables at the beginning of the scope. But here "bar" is declared inside "if", JavaScript doesn't have scope block right. So is this correct. Can someone explain this.