首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

分号 | Semicolons

Semicolons

  • No semicolons. (see: 1, 2, 3) eslint: semi window.alert('hi')???//???ok
  • window.alert('hi');??//???avoid
  • Never start a line with (, [, `, or a handful of other unlikely possibilities. This is the only gotcha with omitting semicolons, and standard protects you from this potential issue. (The full list is: [, (, `, +, *, /, -, ,, ., but most of these will never appear at the start of a line in real code.) eslint: no-unexpected-multiline //???ok;(function?()?{??window.alert('ok')}())?//???avoid(function?()?{??window.alert('ok')}()) //???ok;[1,?2,?3].forEach(bar)?//???avoid[1,?2,?3].forEach(bar) //???ok;`hello`.indexOf('o')?//???avoid`hello`.indexOf('o') Note: If you're often writing code like this, you may be trying to be too clever. Clever short-hands are discouraged, in favor of clear and readable expressions, whenever possible. Instead of this: ;[1,?2,?3].forEach(bar) This is strongly preferred: var?nums?=?[1,?2,?3]nums.forEach(bar)

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com