JS FUNCTIONS
JS FUNCTIONS
Function Expression:
A function can also be stored in a variable, which is known as a
function expression. This function may or may not have a name.
Example:
Function Parameters:
In JavaScript, function parameters act as placeholders for values that
the function can accept when it’s called.
JavaScript Function Parameters
1. Default Parameters
Default parameters allow you to set initial values for named
parameters if no value or undefined is passed when the function is
called.
Syntax:
Example:
2. Rest Parameters
Rest parameters allow a function to accept an indefinite number of
arguments, which are grouped into an array.
3. Arguments Object
The arguments object is an array-like object accessible within all non-
arrow functions. It contains the values of the arguments passed to
the function.
Example:
4. Pass by Value
In JavaScript, when you pass a primitive value (like numbers or
strings) to a function, the function receives a copy of that value.
Changing the parameter inside the function does not affect the
original value outside the function.
Example: