Passing values in JS in objects is by reference

Passing in a primitive type variable like a string or a number, the value is passed in by value. Passing in an object, however, passes it in by reference.

Here is an example:

function printStudent(student){
    for(var i in student.marks){
        console.log(marks[i].subject+" s ocentka "+marks[i].score);
var marks=[ {subject:"OOP",score:'6'} ];
var student = {name:"Dido",marks:marks};

Leave a Reply

Your email address will not be published. Required fields are marked *