Last active
March 1, 2017 10:37
-
-
Save underwindfall/abcb6f0a0c81f671b2bb3e0e2761e34e 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
// 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); | |
}); | |
}); | |
}); |
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