无分号js风格注意的三个问题

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

// 1.(
function say() {
  console.log('hello world')
}

// TypeError: say(...) is not a function
say()

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

// 3.`
// ` 是 EcmaScript 6 中新增的一种字符串包裹方式,叫做:模板字符串
// 它支持换行和非常方便拼接变量
var foo = `
 你们好就好好
 咕咕嘎嘎   啦啦啦
 打撒打算的
哈哈哈`
console.log(foo)

;`hello`.toString()

https://blog.csdn.net/weixin_45525272/article/details/113852777

posted @ 2021-09-16 12:19  小兜兜me  阅读(28)  评论(0编辑  收藏  举报