showing results for - "are parameters modified in javascript"
Christopher
27 Jan 2020
1//Normal variable, No.
2function square(x) {
3    x = x * x;
4    return x;
5}
6var y = 10;
7var result = square(y);
8console.log(y); // 10 -- no change
9console.log(result); // 100    
10            
11//Objects like struct sub variables, Yes.
12function turnOn(machine) {
13    machine.isOn = true;
14}
15
16var computer = {
17    isOn: false
18};
19
20turnOn(computer);
21console.log(computer.isOn); // true;
similar questions
queries leading to this page
are parameters modified in javascript