0% found this document useful (0 votes)
58 views

Function: // Function Declaration / Function Statement

1) Functions allow for organizing code into reusable sections. A function is defined with the function keyword followed by a name and optional parameters in parentheses. Code within the function is contained in curly braces. 2) Functions can optionally return a value using the return keyword. Once a function returns a value, any remaining code in the function will not execute. 3) To invoke or call a function, the function name is written followed by parentheses. Any parameters passed during invocation can be accessed within the function code.

Uploaded by

Madan Chaudhary
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Function: // Function Declaration / Function Statement

1) Functions allow for organizing code into reusable sections. A function is defined with the function keyword followed by a name and optional parameters in parentheses. Code within the function is contained in curly braces. 2) Functions can optionally return a value using the return keyword. Once a function returns a value, any remaining code in the function will not execute. 3) To invoke or call a function, the function name is written followed by parentheses. Any parameters passed during invocation can be accessed within the function code.

Uploaded by

Madan Chaudhary
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

< > 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

You might also like