I am a newbie to javascript learning objects. I created an object here is the code
const address = {
street: "",
city: "",
zipcode: "",
showAddress: function() {
return (street+city+zipcode);
}
};
when I type:
address.showAddress();
It shows the error:
"Uncaught ReferenceError: street is not defined
at Object.showAddress (index.js:237)
at <anonymous>:1:
9"
I just googled the error and couldn't find a solution. at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_defined I couln't understand why this error is happening in this scope. at developer .mozilla.org it is written that function can access all variables and functions defined inside the scope in which it is defined.
The question is:
why the member function can't access properties of it's own object. I studied oop concepts in javascript and there I can access properties of object easily by it's own method. I hope that the questio is clear.