i'm trying to "play" with the this keyword, in order To understand it better. i create an object name "car" with propertie "onRoad", that his value is function as you can see.
var car = {
color: "black",
type: "bmw",
year: 2013,
onRoad: function onTheRoad() {
console.log(2017 - this.year);
function demo() {
console.log(2020 - this.year);
}
demo();
}
};
car.onRoad();
the this keyword work great in the first function, and my output is 4 Just what I wanted.but for some reason in the "demo" function when i was expected that the output will be 7,instead i get output of NaN. i guess that There is a connection to the this keyword. but i do not understand why it's not refers to the "car" object like in the "onTheRoad" function.(the "demo" function is nested inside "onTheRoad" function). Thanks in advance(: