Answers for "are parameters modified in javascript"

0

are parameters modified in javascript

//Normal variable, No.
function square(x) {
    x = x * x;
    return x;
}
var y = 10;
var result = square(y);
console.log(y); // 10 -- no change
console.log(result); // 100    
            
//Objects like struct sub variables, Yes.
function turnOn(machine) {
    machine.isOn = true;
}

var computer = {
    isOn: false
};

turnOn(computer);
console.log(computer.isOn); // true;
Posted by: Guest on October-21-2020

Code answers related to "are parameters modified in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language