Last active
March 1, 2017 10:34
-
-
Save underwindfall/831518e7029e8a510ec51ad49e1d9986 to your computer and use it in GitHub Desktop.
Answers of Es6katas [http://es6katas.org/]
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
// 7: block scope - let | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('`let` restricts the scope of the variable to the current block', () => { | |
describe('`let` vs. `var`', () => { | |
it('`var` works as usual', () => { | |
if (true) { | |
var varX = true; | |
} | |
assert.equal(varX, true); | |
}); | |
it('`let` restricts scope to inside the block', () => { | |
if (true) { | |
let letX = true; | |
} | |
assert.throws(() => console.log(letX)); | |
}); | |
}); | |
describe('`let` usage', () => { | |
it('`let` use in `for` loops', () => { | |
let obj = {x: 1}; | |
for (let key in obj) {} | |
assert.throws(() => console.log(key)); | |
}); | |
it('create artifical scope, using curly braces', () => { | |
{ | |
let letX = true; | |
} | |
assert.throws(() => console.log(letX)); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details: http://es6.ruanyifeng.com/#docs/let