### Passed by value and passed by reference

Passed by value and passed by reference

  • Passed By Values Are Primitive Data Types.

Consider the following example:

Here, the a=432 is a primitive data type i.e. a number type that has an assigned value by the operator. When the var b=a code gets executed, the value of ‘var a’ returns a new address for ‘var b’ by allocating a new space in the memory, so that ‘var b’ will be operated at a new location.

Example:

var a = 432;

var b = a;

Passed_by_values_new

  • Passed by References Are Non-primitive Data Types.

Consider the following example:

The reference of the 1st variable object i.e. ‘var obj’ is passed through the location of another variable i.e. ‘var obj2’ with the help of an assigned operator.

Example:

var obj = { name: “Raj”, surname: “Sharma” };

var obj2 = obj;

Passed_by_reference

2 Likes

Great !!! @nagesh28katke