Skip to content

Instantly share code, notes, and snippets.

@underwindfall
Last active March 1, 2017 10:37
Show Gist options
  • Save underwindfall/abcb6f0a0c81f671b2bb3e0e2761e34e to your computer and use it in GitHub Desktop.
Save underwindfall/abcb6f0a0c81f671b2bb3e0e2761e34e to your computer and use it in GitHub Desktop.
Answers of Es6katas [http://es6katas.org/]
// 8: block scope - const
// To do: make all tests pass, leave the asserts unchanged!
describe('`const` is like `let` plus read-only', () => {
describe('scalar values are read-only', () => {
it('number', () => {
const constNum = 0;
//constNum = 1;
assert.equal(constNum, 0);
});
it('string', () => {
const constString = 'I am a const';
//constString = 'Cant change you?';
assert.equal(constString, 'I am a const');
});
});
const notChangeable = 23;
it('const scope leaks too', () => {
assert.equal(notChangeable, 23);
});
describe('complex types are NOT fully read-only', () => {
it('array', () => {
const arr = [42, 23];
// arr[0] = 0;
assert.equal(arr[0], 42);
});
it('object', () => {
const obj = {x: 1};
obj.x = 3;
assert.equal(obj.x, 3);
});
});
});
@underwindfall
Copy link
Author

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