Js Functions
Js Functions
WHAT IS A FUNCTION?
Function is a group of statement that together perform a specific task
We divide a code into separate functions
Functions usually take in data, process it and return a result
It can be used over, over and over again
ADVANTAGES OF FUNCTION
Avoid repetition of code
Increase program readability
Divide complex problem into simpler segments
Reduce chance of error
Modifying program becomes easier
TYPES OF FUNCTIONS
Inbuilt
Library provide numerous inbuilt functions
Example :
toString() converts an object into the string.
equals() checks if two objects are equal.
• Defined By User
COMPONENTS OF FUNCTION
Declaration of a function :
A JavaScript function is defined with the function keyword, followed by
a name, followed by parentheses ().
Tells the browser:
name of function,
input parameters
The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)
Syntax :
function name(parameter1, parameter2, parameter3) {
// code to be executed
}.
Defination of a function
Actual body