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

307
Vistas
console.log("x:", x) or console.log("x:" + x)?

Why is console.log("x:", x) better than console.log("x:" + x)? I have a category object that contains categoryId and name. When I write console.log("x:", x), the console gives me Data: (5) [{…}, {…}, {…}, {…}, {…}]

However, if I use console.log("x:" + x), the console gives me Data: [object, object][object, object][object, object][object, object][object, object]

I wonder what is the reason and why there is a difference?

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

0

The reason why using console.log("Data:"+x) does not output the desired result when console.log("Data:",x) does (x is the variable name of your object) is because of the way that JavaScript works. In the first example, Javascript will first evaluate the string passed as a parameter (the "Data:"+x).

Since JavaScript can only convert an object to a string when it is passed as an argument to a JSON.stringify() function, the object will not be preserved within the evaluation of the string, and it will instead be replaced with "[object Object]".

Javascript will interpret console.log("Data:",x) differently. The first parameter, "Data:", is passed and logged into the console first. In the same line, the data object is logged as an object datatype, as the object is not next to a string and therefore will not be evaluated as a string before being logged into 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