猿问
函数提升的疑惑
function text () {
conssole.log(1)
}
console.log(text());会打印出2,为什么不是1
function text () {
conssole.log(2)
}
ITMISS
浏览 381
回答 1
1回答
眼眸繁星
打出来的是 2 和 undefined 把2 是 第二个text()执行;undefined 是因为 text()没有返回值函数提升,这段代码等价于:function text () { console.log(1);}function text () { console.log(2);}console.log(text());函数按顺序进行提升,后者覆盖了前者
0
0
0
随时随地看视频
慕课网APP
相关分类
JavaScript
我要回答