Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

48
Vistas
Difference between what's passed natively to console.log and toString

In the following example:

let s = {x: 1, y: 1};
console.log(s, s.toString());

Where is the '[object Object]' method defined? Why does printing an object evaluate to something different than doing object.toString() ?

7 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Various environments' consoles are generally intended for (and hence optimized for) debugging. If you log an object, the console is likely to show you a full, readable, interactive view of the object. The console does not convert logged values to strings before displaying them - that wouldn't be useful for debugging.

When an object has Object.prototype.toString called on it, it's required to go through these steps in the specification, which will result in [object SOMETHING] being logged, where SOMETHING may be Array, Function, etc, or Object if none of those special cases match. For a plain object, none of the special cases match, so you get [object Object].

7 months ago · Juan Pablo Isaza Denunciar

0

Replace s.string() with JSON.stringify()...

Refer here... What's the difference in using toString() compared to JSON.stringify()? for further

7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.