Function declaration and expression in js, js function declaration expression
// Function declaration: function name (){}
// Function expression: function name (writable or not) () {}: anonymous function expression
// Function aaa () {}: function declaration
// Var a = function aaa () {}: name function expression
// Var a = function () {}: anonymous function expression
(Function aaa () {}): Expression
~ Function aaa (){}
-Function aaa (){}
+ Function aaa (){}
! Function aaa (){}
/Differences:
// 1. The function expression can be executed directly in parentheses, but the function declaration is not.
// 2. The function declaration can be parsed in advance.
// Function aaa () {alert (1 );}();
// Var a = function aaa () {alert (1 );}();
//~ Function aaa () {alert (1 )}();
/* If (true ){
Function aaa (){
Alert (1 );
}
}
Else {
Function aaa (){
Alert (2 );
}
}
Aaa ();*/
If (true ){
Var a = function aaa (){
Alert (1 );
}
}
Else {
Var a = function aaa (){
Alert (2 );
}
}
A ();
/*
Var a = function aaa (){
Alert (1 );
Alert (typeof aaa); // can be found internally
}
// ();
Aaa (); // cannot be found outside */
(Function aaa () {alert (1 )})
Aaa ();
Function aaa (){
Return bbb ();
}
/* Function bbb (){
Debugger;
}*/
Var bbb = (function bbb (){
Return function (){
Debugger;
}
})();
Aaa ();
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.