Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
member function is not able to access its member properties?

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try this

You have to use a 'this' to use inside the key. If I'm right the only way is to use 'this'. Check the picture and write me if it work.

const address = {
street: "a",
city: "b",
zipcode: "c",
showAddress: function() {
    return (this.street+this.city+this.zipcode);
}

};

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!