小编ank*_*aha的帖子

IIFE内可变吊装(延迟解析)

我在下面的场景中得到了一个非常奇怪的输出:

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 hoisting

6
推荐指数
1
解决办法
230
查看次数

索引为Number.MAX_VALUE的Javascript数组

任何人都可以解释这种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尝试了这个.

有谁知道这背后的原因?

javascript arrays

4
推荐指数
1
解决办法
107
查看次数

标签 统计

javascript ×2

arrays ×1

hoisting ×1