on
Passing value or reference??
A little introduction on pass by value v/s pass by reference.
Pass By Value
In Pass by Value, functions are called directly by passing the value of the variable in the form of argument.
If programmer changes the argument inside the function it doesn’t affect the variable which is globally passes or is outside the function.
Javascript often pass by value, so if someone changes the value of the variable; the basic or primary value will not get changed (String or number).
Example:
Pass By Reference
Basics data types in Javascript like number, string and boolean pass by value whereas data types like objects and arrays are pass by reference.
In Pass by Reference, functions are called by directly passing the address of the variable as the argument. Changing the argument inside the function affects the variable which is passed from outside the function.
Example: