Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda