What is pass by Value and Pass by reference in JavaScript

What is pass by Value and Pass by reference in JavaScript

Pass by value works with primitive data type

let a = 5;
let b = a;
b= b+5;
console.log(a);//5
console.log(b);//10

Pass by Refnrece Used in non Primitve::

const obj1 = {
user:"jigar",
pass:"pass"
}

const obj2= obj1;

obj2.pass = 'dd';

console.log(obj1);//{user: 'jigar', pass: 'dd'}
console.log(obj2);//{user: 'jigar', pass: 'dd'}

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment