1. 保留字可直接作为对象的属性: obj.for = "Mack"
Starting in ECMAScript 5, reserved words may be used as object property names "in the buff". This means that they don't need to be "clothed" in quotes when defining object literals.
2. 变量作为key,可直接用[]括起来: b = "name"; a = {[b]: "Jack"}; ===> a = {"name":"Jack"}
Starting in ECMAScript 2015, object keys can be defined by variable using bracket notation upon being created. {[phoneType]: 12345} is possible instead of just var userPhone = {}; userPhone[phoneType] = 12345.
3. 数组 pop()、push(e)在尾部删除和添加;shift()、unshit(e)在头部删除和添加
4. for...of 遍历
5. arguments 默认的参数数组
eg.
function add() {
var sum = 0;
for(const a of arguments) { //ECMAScript introduced the more concise for...of loop for iterable objects
sum += a;
}
return sum;
}
add(3,4,5); // 12
也可指定 参数数组 function add(...args) {} OR function add(first, ...args) {}, just like Java , you cannot put ...arg before first;
Starting in ECMAScript 5, reserved words may be used as object property names "in the buff". This means that they don't need to be "clothed" in quotes when defining object literals.
2. 变量作为key,可直接用[]括起来: b = "name"; a = {[b]: "Jack"}; ===> a = {"name":"Jack"}
Starting in ECMAScript 2015, object keys can be defined by variable using bracket notation upon being created. {[phoneType]: 12345} is possible instead of just var userPhone = {}; userPhone[phoneType] = 12345.
3. 数组 pop()、push(e)在尾部删除和添加;shift()、unshit(e)在头部删除和添加
4. for...of 遍历
5. arguments 默认的参数数组
eg.
function add() {
var sum = 0;
for(const a of arguments) { //ECMAScript introduced the more concise for...of loop for iterable objects
sum += a;
}
return sum;
}
add(3,4,5); // 12
也可指定 参数数组 function add(...args) {} OR function add(first, ...args) {}, just like Java , you cannot put ...arg before first;
6. Just like C and Java, the && and || operators use short-circuit logic,
which means whether they will execute their second operand is dependent on the first.
var name = o && o.getName();
var name = cachedName || (cachedName = getName());
7. parseInt('123huh') = 123; parseFloat('10.2uyt') = 10.2;
解析到不能识别的为止,前面已解析的作为结果;parseInt('12a', 16)第二个参数可指定进制,parseFloat()永远是十进制
The parseInt() and parseFloat() functions parse a string until they reach a character that isn't valid for the specified number format, then return the number parsed up to that point.
which means whether they will execute their second operand is dependent on the first.
var name = o && o.getName();
var name = cachedName || (cachedName = getName());
7. parseInt('123huh') = 123; parseFloat('10.2uyt') = 10.2;
解析到不能识别的为止,前面已解析的作为结果;parseInt('12a', 16)第二个参数可指定进制,parseFloat()永远是十进制
The parseInt() and parseFloat() functions parse a string until they reach a character that isn't valid for the specified number format, then return the number parsed up to that point.