var a=1; var b=2和var a=b=1和var a=1,b=2的区别

1
2
3
4
5
6
7
8
9
10
11
12
13
function fn () {
var a = 1,b = 2
var c = d = 3
e = 4
}

fn()
console.log(a) // a is not defined
console.log(b) // b is not defined
console.log(c) // c is not defined
console.log(d) // 3
console.log(e) // 4

var a = 1,b = 2

a, b都是局部变量

var c = d = 3

c局部变量,d是全局变量

e=4

e是全局变量