js function declaration

JS function declaration in three ways:

  1. Function expression: function operator to create functions, expressions can be stored in variables or object properties in the anonymous function is often called, console.log (h.name); you can see the print empty '. "

  2. Function declaration: named function, and its function can be called anywhere in scope, its function is to create a named function, you can prove it console.log (h.name); see print as "h" . this function can be later assigned to a variable code by the function name or an object property

  3. Function () constructor: not recommended for this use, easy to go wrong
var a = h
function h(){
    console.log(1)
}
console.log(a) // ƒ h(){}
            

Guess you like

Origin www.cnblogs.com/bingery/p/11331074.html