Call by value of a primitive data is Js

Rita Cascante Makarova
2 min readApr 25, 2018

--

String, Number, Boolean, null and undefined are primitive types of data and this type of data is passed by value.

When we create a variable and store a primitive value in it, we create in the memory a specific place for the variable and the value.

var box1 = ‘shoes’var box2 = 20
How it looks like in the memory

When we create another variable and assign to it the value of the variables that we created at the first place, we don’t change one variable for the other, we copy the values and assign them to the new variables.


var box1 = ‘shoes’
var box2 = 20
var newBox1 = box1
var newBox2 = box2
console.log(box1, box2, newBox1, newBox1); //Returns: ‘shoes’, 20, ‘shoes’, 20
This is how all our variables and their values are stored in the memory

Since this variables are stored in different parts of the memory, if we change the value ofnewBox1,it will not affect the value ofbox1, even though assigned box1 as a value of newBox1

var box1 = ‘shoes’
var box2 = 20
var newBox1 = box1
var newBox2 = box2
//Reasigning valuesnewBox1 = 'dress'
newBox2 = 5
console.log(box1, box2, newBox1, newBox1);
//Returns: ‘shoes’, 20, ‘dress’, 5
This is how our data is stored now in the memory

References

Javascript pass by Value vs pass by Reference tutorial

--

--