< > iLoveCoding
JavaScript Cheatsheet
Page 2
Learn JavaScript Correctly (Video course) https://ilovecoding.org/courses/js2
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.
Invoke a function Passing parameter(s) to a function (optional)
Invoking, calling or running a function all mean the same At the time of invoking a function, parameter(s)
thing. When we write the function name, in this case may be passed to the function code.
someName, followed by the brackets symbol () like this
someName(), the code inside the function gets executed.
iLoveCoding
"Don't just learn JavaScript - Become a Full-Stack JavaScript Developer" https://iLoveCoding.org