0

THIS QUESTION HASN'T BEEN ANSWERED, THE SECONDARY ASPECT IS NOT THE POINT OF THE QUESTION

So i've come across some unexpected behaviour and was looking for an explanation. I'm assuming it's related to how Buffer formats data and how process.stdout.write reads data.

When running the below code, my output is 3 emoticons, a black and white smiley face - along with a heart. However when i run the same code and check it with console.log, which i was led to believe was just a wrapper for process.stdout.write, then it outputs the Buffer. What is the reason for this? My guess is that stdout.write reads the buffer in an encoding that designates the buffer as emoticon characters but if so then why doesn't console.log do the same?

const buf2 = Buffer.from([1,2,3])

process.stdout.write(buf2)
  • The terminal program you're using uses some old DOS code page. If you look [here](https://en.wikipedia.org/wiki/Code_page_850), specifically the character set image, you'll see that the first four characters shown are a blank space (which would be "0"), a black smiley face, a white smiley face, and a heart. – robertklep Aug 03 '22 at 16:20
  • Thank you! That's really spot on for you to answer this after it was incorrectly shutdown! I wish i could credit you with answering my question. – HighlandRocket Aug 03 '22 at 18:08
  • When I read your question, you're asking why `console.log()` doesn't do the same as `process.stdout.write()`, which seems very much a duplicate. It's unclear that the goal of your question is to get an explanation why it's showing those specific characters. – robertklep Aug 03 '22 at 18:51

1 Answers1

-1

This is well explained here: Difference between "process.stdout.write" and "console.log" in node.js?

In a few words, console.log uses process.stdout but performs formatting before the output

Shmyhelskyi
  • 157
  • 4