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

159
Views
Why undefined? Even if the this pointer is pointing to the same object and also the strict mode is used
"use strict";
const data = {
firstName: "myName",
lastName: this.firstName,
};
console.log(data.lastName);

Output is undefined. Can anyone explain why it's happening?

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

0

Because this does not work like that. When you are defining your object literal (data), this does not point to that literal - to see what this actually is, do a console.log(this).

You can solve your problem by modifying your code like this:

"use strict";
const data = {
    firstName: "myName"
}
data.lastname = data.firstname;

Also, I recommend reading up on how this works to avoid confusion in the future - this is a bit weird in Javascript.

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!