JS: Define Function
Create a Function
There are 3 ways to create a function.
- By the keyword
function
. - By Arrow Function expression. Most simple. 〔see JS: Arrow Function〕
- By constructor with keyword
Function
. 〔see JS: Function Constructor〕
Keyword “function”
The syntax is:
function name (parameters) {body_statements}
Return Statement
In the function body, you can have
0 or more
return expr
.
When program reaches the return statement, it'll exit the function, and return the value.
Function without return statement returns the value undefined
.
for detail, see JS: Function Parameters and other pages.
JavaScript, Function
- JS: Define Function
- JS: Arrow Function
- JS: Function Parameters
- JS: arguments Object
- JS: Function Rest Parameters
- JS: Function Argument Default Value
- JS: Function Argument Destructure
- JS: Function Declaration vs Function Expression
- JS: Closure
- JS: Function Call, Apply, Bind
- JS: Functional Programing
- JS: Function Pipe 🚀
- JS: Function Object
- JS: Function Constructor
- JS: Function.prototype