🔧 Function declaration and Function Expression
Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to
The function expression is nearly similar to the function declaration, but there are some differences.
The function declaration is created by first declaring the function keyword, followed by a code block where we put our code to be executed.
Function name(parameters){
Our code to be executed
}
name(argument);
And meanwhile, the function expression can be stored in a variable, which is then used as a function.
Const name = function ( parameters a, parameter b){
Our code to be executed
};
name(argument);
As an expression, the semicolon is placed at the end of the code block because that is where it is expected to be.
Hoisting
hoisting allows you to use functions and variables before they are declared.
This is done with function declaration but not with function expression.
Examples
name(argument);
Function name(parameters){
Our code to be executed
}
This is a function declaration; the code will be executed because JavaScript hoisting accepts it.
name(argument);
Const name = function ( parameters a, parameter b){
Our code to be executed
};
Meanwhile, because this is a function expression, the code will not run because JavaScript hoisting does not accept it.
It’s will display undefined.
I hope this is of great assistance to someone out there.
...
🔧 Function Declaration vs Function Expression
📈 50.83 Punkte
🔧 Programmierung
🔧 Variables and Constants: Declaration and Usage
📈 24.13 Punkte
🔧 Programmierung
🔧 IIFE(immediately-Invoked function Expression)
📈 21.71 Punkte
🔧 Programmierung
🔧 Immediately Invoked Function Expression (IIFE)
📈 21.71 Punkte
🔧 Programmierung
🐧 Declaration of Freedom of Software on 27-Sep-1983
📈 20.78 Punkte
🐧 Linux Tipps