当前位置: 首页 > 工具软件 > age > 使用案例 >

报错:ReferenceError: Cannot access 'age' before initialization

融伯寅
2023-12-01

                                      报错:ReferenceError: Cannot access 'X' before initialization

1、以下代码报错:ReferenceError: Cannot access 'age' before initialization

function fn (age){
    if (typeof age === 'undefined'){
        console.log(age);
        let age = 66;
    }
}

fn();

2、解决办法:

    将let换成var,let只能声明一次

 

 类似资料: