重学JavaScript笔记

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;
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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值