Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!