search

Home  >  Q&A  >  body text

javascript - Named function cannot be accessed outside the function

var func2 = function func1() {
        console.log(1010)
        // console.log('func1', func1)
    }

    function func3 () {
        console.log(1010)
    }

    func3() // 1010
    func2() // 1010
    func1() // func1 is not defined

func1 cannot be accessed, please explain, please explain

过去多啦不再A梦过去多啦不再A梦2754 days ago656

reply all(1)I'll reply

  • 学习ing

    学习ing2017-06-12 09:32:01

    The function you create is created through function expression, not through function declaration statement, function name can only be used in this function expression. Notefunction declaration statements and Function expressionsThe way to define functions is different.

    Refer to the Javascript Definitive Guide 8.1 Function Definition section:

    reply
    0
  • Cancelreply