let add = 1
function add(){}
>Uncaught SyntaxError: Identifier 'add' has already been declared
//会报错的原因是,add函数会提升,let不允许已经声明过的变量再声明。但是var可以
let fn = function(){}
add(1,2)
let add = function(x,y){return x+y}
function fn(){
console.log(arguments)
console.log(this)
}
console.log(this)//window
let fn = () => console.log(this)
fn()//window
fn.call({name:'frank'})//window
function (){
var a = 2
console.log(a)
}()
//js认为以上的语法是错误的,于是程序员发现了下面代码可以运行
!function (){
var a = 2
console.log(a)
}()
//新版的JS如何造局部变量呢
{
let a = 2
console.log(2)
}
console.log('hi')
(function(){
var a = 2
console.log(a)
}())
>Uncaught TypeError: console.log(...)is not a function at....