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

114
Views
Not defined object

I'm trying to get my object to print wolverine's email and name in the console. However, wolverine is showing up in the console as "not defined". How is this possible when it's a part of a class called new User? Any help would be appreciated.

class User {
  constructor(email, name) {
    this.email = email;
    this.name = name;
  }
}
let userOne = new User('wolverine@marvel.com', wolverine);
let userTwo = new User('sabertooth@marvel.com', sabertooth);

console.log(userOne);
console.log(userTwo);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You're getting undefined (or, in strict mode, an error) because the variables wolverine and sabertooth aren't assigned, so their value is... undefined.

You are probably looking to pass the names as strings too:

let userOne = new User('wolverine@marvel.com', 'wolverine');
let userTwo = new User('sabertooth@marvel.com', 'sabertooth');

Alternatively, you may be looking to have the names in variables first, then pass the variables in:

let nameOfGuyWithHandBlades = 'wolverine';
let totallyATiger = 'sabertooth';
let userOne = new User('wolverine@marvel.com', nameOfGuyWithHandBlades);
let userTwo = new User('sabertooth@marvel.com', totallyATiger);
about 4 years ago · Juan Pablo Isaza Report

0

That is happening you are passing wolverine and sabertooth as variables, not as strings.

Correct usage:

let userOne = new User('wolverine@marvel.com', 'wolverine');
let userTwo = new User('sabertooth@marvel.com', 'sabertooth');
about 4 years ago · Juan Pablo Isaza Report

0

Passing wolverine like that treats it as a variable, and it clearly can't find it.

If it's a string, like you did with the email, you need quotes '.

let userOne = new User('wolverine@marvel.com', 'wolverine');
let userTwo = new User('sabertooth@marvel.com', 'sabertooth')
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!