The problem of function declaration

in variable declaration

    var fn = function fn2() {}
    
    console.log(fn) // function
    console.log(fn2) // Uncaught ReferenceError: fn2 is not defined

Why is the fn2 here not defined?? Is it because it"s in fn2"s own scope?

Mar.30,2021

fn2 can only be referenced in fn2


function fun2 () {}
var fn = fn2
console.log (fn)
console.log (fn2)


javascript the definitive guide 8.1

An identifier that names the function. The name is a required part of function declaration statements: it is used as the name of a variable, and the newly defined function object is assigned to the variable. For function definition expressions, the name is optional: if present, the name refers to the function object only within the body of the function itself.

that is, the identifier (function name) in the assignment function definition is optional, and even if provided, it can only be referenced in the function body;

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ebe4c7-48788.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ebe4c7-48788.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?