Skip to content

Instantly share code, notes, and snippets.

@underwindfall
Last active March 1, 2017 10:34
Show Gist options
  • Save underwindfall/831518e7029e8a510ec51ad49e1d9986 to your computer and use it in GitHub Desktop.
Save underwindfall/831518e7029e8a510ec51ad49e1d9986 to your computer and use it in GitHub Desktop.
Answers of Es6katas [http://es6katas.org/]
// 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));
});
});
});
@underwindfall
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment