我在下面的场景中得到了一个非常奇怪的输出:
function test(){
var test=123;
console.log(test)
}
// this output : 123
(function test(){
var test=123;
console.log(test)
})()
// this output: 123
Run Code Online (Sandbox Code Playgroud)
但是在使用下面的代码时
(function test(){
test=123;
console.log(test)
})()
//output:
function test(){
test=123;
console.log(test)
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释一下.
任何人都可以解释这种javascript数组的行为
//create an empty array
var arr=[];
//added an entry with index Number.MAX_VALUE
arr[Number.MAX_VALUE]="test"
//On printing the array, its showing as empty
arr
//[]
//even its length=0
arr.length
//0
//on accessing the same value its showing the correct value
arr[Number.MAX_VALUE]
//"test"
Run Code Online (Sandbox Code Playgroud)
我用Number.MIN_VALUE尝试了这个.
有谁知道这背后的原因?