Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda