the following factory function has on = false
.
function Radio(mode) {
let on = false;
return {
mode: mode,
turnOn: function () {
on = true;
},
isOn: function () {
return on;
}
};
}
If I created an object using this factory function and used the function fmRadio.turnOn();
inside it to change the value of on
to be true
like in the following lines..
let fmRadio = Radio('fm');
fmRadio.turnOn();
The output of fmRadio.isOn();
will be on = true
So, Where does on
variable change? I mean it's not part of the fmRadio
object created..if we tried to call it it will return undefined
fmRadio.on;
//undefined
Does it change the value of on
in the original factory function?