Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • B008-变量提升★

B008-变量提升★

1

function a() {

}
var a;
console.log(typeof a);  

答案

function a() {}

2

var c = 1;
function c(c) {
    console.log(c);
}
c(2)

答案

报错 c is not a function
 function fn(a,c) {
     console.log(a)
     var a= 123;
     console.log(a)
     console.log(c)

 }
fn(1,2)

答案:

1
123
2

初始化时候a 为undefined,传入参数a为1,a就为1了

<script>
   function fn(a,c) {
    console.log(a)
    var a= 123;
    console.log(a)
    console.log(c)

    function a() {}

    if(false) {
        var d = 678
    }

    console.log(d)
    console.log(b)

    var b = function() {};

    console.log(b)

    function c() {}
    console.log(c)

}
fn(1,2)

输出:
function a() {}
123
function c() {}
undefined
undefined
function () {}
function c() {}

传入参数a为1,但是下面有个函数a,函数会把之前的覆盖因此,打印a时候就是 function a() {

}

Edit this page
最近更新: 2025/6/27 02:24
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人