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

279
Vistas
Why after call an expression with new, the console return undefined

After I create an object of primitive type on javascript console, it return undefine

for example

var john = new String("John");

undefined

But after continue to type

john

String {'John'}

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

When typing code into the console, what it "reads back" to you after you press enter is the completion value of the last statement.

Variable declarations do not result in any completion value, so it reads back to you undefined.

But, a statement referencing an existing identifier will give you the value in the identifier - which, in this case, is a String object.

(But, keep in mind that there's almost no good reason to use the primitive constructors - better to use var john = 'John';)

about 4 years ago · Juan Pablo Isaza Denunciar

0

When you declare a variable and assign a value to it in console, it just sets the variable to the value you assigned it, it doesn't return anything.

So, if you open dev tools console and type:

let a = 1;

console will report undefined

if you then type a into console and press return, 1 will be displayed as the value returned by variable name a.

What you described is normal behaviour for the console.

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