Function: // Function Declaration / Function Statement
Function: // Function Declaration / Function Statement
JavaScript Cheatsheet
Page 2
4 Function
Parameters / Arguments
A function is simply a bunch of code bundled in a section. This bunch of code ONLY runs when the (optional)
function is called. Functions allow for organizing code into sections and code reusability. A function can optionally
take parameters (a.k.a
Using a function has ONLY two parts. (1) Declaring/defining a function, and (2) using/running a function. arguments). The
function can then use
this information within
Name of function // Function declaration / Function statement
the code it has.
Thats it, its just a name
function someName(param1, param2){
you give to your function.
Tip: Make your function
names descriptive to what Code block
// bunch of code as needed... Any code within the curly
the function does.
var a = param1 + "love" + param2; braces { ... } is called a
"block of code", "code
return a;
block" or simply "block".
Return (optional)
} This concept is not just
A function can optionally
limited to functions. "if
spit-out or "return" a value
statements", "for loops"
once its invoked. Once a // Invoke (run / call) a function and other statements
function returns, no further
someName("Me", "You") use code blocks as well.
lines of code within the
function run.
iLoveCoding
"Don't just learn JavaScript - Become a Full-Stack JavaScript Developer" https://iLoveCoding.org