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??

TheZ
  • 3,663
  • 19
  • 34
G-Force
  • 345
  • 3
  • 10
  • What do you mean, "I run this in Windows PowerShell?" PowerShell is its own unique programming environment, separate from Node. – Heretic Monkey Feb 01 '21 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. – G-Force Feb 01 '21 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. https://i.stack.imgur.com/GLu2a.png – Heretic Monkey Feb 01 '21 at 18:49
  • thanks the quick responses @HereticMonkey. It seems something different. I too can use node REPL mode and get this, but reading in this from my JS file, it wants to convert to "?"s for many of my string characters. in a web mode, I would be putting in a using-charset type decl...I don't have that here. But the CMD and PS env's still do the same thing. Any further advice? – G-Force Feb 01 '21 at 19:11
  • 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. – Heretic Monkey Feb 01 '21 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. – G-Force Feb 01 '21 at 20:13

0 Answers0