I have the next piece of code:
function Server() {
this.isStarted = false;
// var isStarted = false;
function status() {
return isStarted;
}
console.log(status());
}
var a = new Server()
When I run it I get
ReferenceError: isStarted is not defined
at status (/a/fr-05/vol/home/stud/yotamoo/workspace/ex4/text.js:7:10)
at new Server (/a/fr-05/vol/home/stud/yotamoo/workspace/ex4/text.js:10:14)
at Object.<anonymous> (/a/fr-05/vol/home/stud/yotamoo/workspace/ex4/text.js:
However if I change this.isStarted = false; to var isStarted = false; everything works fine.
Does anyone care to explain why?
Thanks