0

At Mozilla.org:

const icons = 'Hữu';
const index = 1;
console.log(icons.codePointAt(index));
console.log(String.fromCodePoint(icons.codePointAt(index)));
//expected output:
//> 7919
//> "ữ"

This is as I expect.

I run this in windows powershell, and the "ữ" (and similar characters) are converted to a "?", and then the codepoint is also changed as a result. I tried with String.raw as well, and it doesn't seem to changing things.

>63
>?

help??

6
  • What do you mean, "I run this in Windows PowerShell?" PowerShell is its own unique programming environment, separate from Node. Commented Feb 1, 2021 at 18:43
  • i run node, in a powershell window....point being it's on windows, and not in a linux environment when I see the difference in ouputs. Commented Feb 1, 2021 at 18:44
  • It makes a difference. When I run the above code using a Command Window (i.e., cmd.exe) in Windows 10, using the Node REPL, I get the expected output. i.sstatic.net/GLu2a.png Commented Feb 1, 2021 at 18:49
  • 1
    Sounds like you're saving the file with the wrong encoding. Make sure you save it with UTF-8 encoding or something similar, not just ASCII. If I take that code and save it to a JS file with UTF-8 encoding, it runs fine from cmd. It does not run fine from a PowerShell window; I'm guessing the duplicate @mplungjan pointed to will help with that. Commented Feb 1, 2021 at 19:19
  • 1
    @HereticMonkey, so this was the issue...I had saved the file, it apparently didn't take the encoding correctly. I had everything else ok, and the duplicate link for PS, I had also resolved prior. thanks again, I knew it was a stupid error somewhere. Commented Feb 1, 2021 at 20:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.