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
// 1: template strings - basics | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('a template string, is wrapped in ` (backticks) instead of \' or "', function() { | |
describe('by default, behaves like a normal string', function() { | |
it('just surrounded by backticks', function() { | |
var str = `like a string`; | |
assert.equal(str, 'like a string'); |
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
// 2: template strings - multiline | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('template string, can contain multiline content', function() { | |
it('a normal string can`t span across multiple lines', function() { | |
var normalString = 'line1' + | |
'\n' + | |
'line2'; | |
assert.equal(normalString, 'line1\nline2'); |
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
// 3: template strings - tagged | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('tagged template strings, are an advanced form of template strings', function() { | |
it('syntax: prefix the template string with a function to call (without "()" around it)', function() { | |
function tagFunction(s) { | |
return s.toString(); | |
} | |
var evaluated = tagFunction `template string`; |
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
// 4: template strings - String.raw | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('on tagged template strings you can use the `raw` property like so `s.raw`', function() { | |
it('the `raw` property accesses the string as it was entered', function() { | |
function firstChar(strings) { | |
return strings.raw; | |
} | |
assert.equal(firstChar`\n`, '\\n'); |
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
// 5: arrow functions - basics | |
// To do: make all tests pass, leave the asserts unchanged! | |
describe('arrow functions', function() { | |
it('are shorter to write', function() { | |
var func = () => { | |
return 'I am func'; | |
}; | |
assert.equal(func(), 'I am func'); |
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
// 6: arrow functions - binding | |
// To do: make all tests pass, leave the asserts unchanged! | |
class LexicallyBound { | |
getFunction() { | |
return () => this | |
} | |
getArgumentsFunction() { |
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) { |
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; |
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
// 9: object-literals - basics | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('The object literal allows for new shorthands', () => { | |
const x = 1; | |
const y = 2; | |
describe('with variables', () => { | |
it('the short version for `{x: x}` is {x}', () => { |
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
// 10: destructuring - array | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('destructuring arrays makes shorter code', () => { | |
it('extract value from array, e.g. extract 0 into x like so `let [x] = [0];`', () => { | |
let [firstValue] = [1]; | |
assert.strictEqual(firstValue, 1); | |
}); |
OlderNewer