js 需要加分号的情况

以下是一些js必须加分号的情况:

  1. 立即执行函数:
    报错:Uncaught TypeError: xx is not a function
// 没有分号的话 ,Uncaught TypeError: xx is not a function
    let x = 3;
    (function t() {
    
    })()

  1. 数组解构
    报错:Uncaught TypeError: Cannot read properties of undefined (reading ‘xxx’)
// Uncaught TypeError: Cannot read properties of undefined (reading 'xxx')
    const str = '123';
    [1,2,3].map(item=>console.log(item*2))

猜你喜欢

转载自blog.csdn.net/qq_41045651/article/details/131596858