Standardized by a standards body called ECMA. Similar to W3C.
const numbers = [1, 2, 3]
const squares = numbers.map(x => x * x)
const numbers = [1, 2, 3]
const squares = numbers.map(function (x) {
return x * x
})
step1(function (value1) {
step2(value1, function(value2) {
step3(value2, function(value3) {
step4(value3, function(value4) {
// yay
});
});
});
});
var step1 = new Promise(...);
step1.then(step2)
.then(step3)
.then(step4)
.then((value4) => {
// Do something with value4
})
.catch(function (error) {
// Woot
throw new Error('fatal error in promises:' + error.message)
});
var o1 = { a: 1 }
var o2 = { b: 2 }
// clone
var copy = Object.assign({}, o1)
// merge
var obj = Object.assign(o1, o2)
const numbers = [1, 2, 3]
const squares = numbers.map(x => x * x)
const numbers = [1, 2, 3]
const squares = numbers.map(function (x) {
return x * x
})
let total = 30;
let name = 'Laurent';
let msg = `${name} your total is: ${total} (${total*1.05} + tax)`;
console.log(msg); // "Laurent your total is: 30 (31.5 + tax)"
class Person {
constructor(name) {
this.name = name;
}
description() {
return `My name is ${this.name}`
}
}
class Jerk extends Person {
constructor(name) {
super(name);
this.jerk = true;
}
isJerk() {
return this.jerk;
}
}
function f(x, y = 7, z = 42) {
return x + y + z
}
function f (x, y, z) {
if (y === undefined)
y = 7;
if (z === undefined)
z = 42;
return x + y + z;
}
var list = [ 1, 2, 3 ]
var [ a, , b ] = list
[ b, a ] = [ a, b ]
var list = [ 7 ]
var [ a = 1, b = 3, c = 5] = list
/*
a === 7
b === 3
c === undefined
*/
var list = [ 1, 2, 3 ]
var a = list[0], b = list[2]
var tmp = a
a = b
b = tmp