Javascript Function Argument Passing Question 3

Description

Javascript Function Argument Passing Question 3


let myNum = 100;/*  ww  w .  j  a va  2 s  .  co m*/
let myObj = {name:'David', age:12};

function changeVals(num, obj) {
  num = 0;
  obj.name = "Changed";
}

changeVals(myNum, myObj);

console.log(myNum);   
console.log(myObj.name);    


100
Changed

Demonstrates the difference between passing primitive vs reference types as arguments




PreviousNext

Related