JavaScript什么时候必须加分号

代码以 (开头

;(function () {
  console.log('hello')
})()

[ 开头

;['苹果', '香蕉'].forEach(function (item) {
    console.log(item)
 })

代码以`开头

;`hello`.toString()

结论:无论你的代码是否有分号,都建议如果一行代码是以 ([` 开头的,则最好都在其前面补上一个分号。

猜你喜欢

转载自www.cnblogs.com/L-xmin/p/12405565.html