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

74
Vistas
typeof code i think there is something weird

When i delete just x from typeof x and runit gives numberobject as a output with no spaces when i just delete y from type y and run it gives nothing

<!DOCTYPE html>
<html>

<body>

  <h2>JavaScript Strings</h2>

  <p id="demo"></p>

  <script>
    // x is a string
    let x = "John";

    // y is an object
    let y = new String("John");

    document.getElementById("demo").innerHTML =
      typeof x + "<br>" + typeof y;
  </script>

</body>

</html>

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

0

When you create a variable like this; var a = "hello world", you're using a string literal to create the string. But when you create a variable like this; new String("hello world"), you're actually instantiating the "String" object. When replacing a string object, a new object is created each time, but with a string literal, it is only replaced.

The problem that you're mentioning is happening because you are using the typeof() function without any paranthesis, which means your code is trying to use + "<br>" as the arguments. The type of + "<br>" is a number, that's why it's telling you it's a number in the same line as object (The <br> isn't being rendered because you used it in the function). Instead, use 'typeof' like typeof(VAR) instead of typeof VAR.

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