DUET PG Score Card 2021
NHAI Recruitment 2021
Bihar Board 12th Dummy Admit Card 2022
RBI Assistant Notification 2021
Jee Advanced 2021 Result
NIACL Assistant Recruitment 2021
SBI PO Online Form 2021

Pass By Reference Advanced JavaScript for All

var a = {key1: 1, key2: 2};
var b = a;

a.key1 = 3;
console.log(a, b);

[Try to answer it on your own. After that, check the output in the Console tab in the Developer Tools.]


{key1: 1, key2: 2} {key1: 3, key2: 2}
{key1: 1, key2: 2}
{key1: 1, key2: 2}
{key1: 3, key2: 2}
{key1: 3, key2: 2}

Feedback: This option is the correct choice. Notice that both the variables a and b are of non-primitive type – object. This is the example where the variable b is passed the value contained in the variable a. Now, when the value contained in the variable a is changed, there is also an impact on the value of the variable in b. To know more, watch the video that is given in this segment.

Leave a Comment