Skip to content

Instantly share code, notes, and snippets.

View underwindfall's full-sized avatar
🐌
Making Progress

Qifan Yang underwindfall

🐌
Making Progress
View GitHub Profile
// 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');
// 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');
// 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`;
// 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');
// 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');
// 6: arrow functions - binding
// To do: make all tests pass, leave the asserts unchanged!
class LexicallyBound {
getFunction() {
return () => this
}
getArgumentsFunction() {
// 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) {
// 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;
// 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}', () => {
// 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);
});