Problems with es6 variables and scope

first give an example:: const testFun = () = > {

let testParams
const sonFun = () => {
    testParams = 3
}
console.log(testParams)

}
how can I console the value of testParams if I write it like this?

Mar.16,2021

first you have to execute the sonFun method before you can assign a value to testParams


you didn't perform this assignment at all

let testParams
const sonFun = () => {
    testParams = 3
}
sonFun()
console.log(testParams)

const testFun = () => {
        let testParams
        const sonFun = () => {
            testParams = 3
        }
        sonFun()
        console.log(testParams)
    }
    testFun()

let testParams
const sonFun = () => {
    testParams = 3
}
sonFun();
console.log(testParams)

the scope of this arrow function is probably not withdrawn in this code

Menu