0
点赞
收藏
分享

微信扫一扫

JavaScript Error-prone points

  1. when using an arrow function, and want to pass an object 's property by destructuring, even if only one parameter, needs to add a paranthses.
let f = ({name}) => name == "Tom";
  1. when using reduce function ( the higher order function ), if only one element in array, it will return the element.
// it is better.
let name = counted.reduce((a, b) => a.count > b.count ? a : b).name;
// it may be got mistakes when only one element in counted array.
let name = counted.reduce((a, b) => a.count > b.count ? a.name : b.name);
举报

相关推荐

0 条评论