tirithen
tirithen

Reputation: 3527

How to create UTF characters dynamically with JavaScript

I'm trying to use a variable and \u to create an UTF character with Node.js.

var code = '0045';
console.log('\u0045', '\u' + code);

But the output becomes

E u0045

How do I make it

E E

How do I create the character and store it in a variable?

Upvotes: 4

Views: 1979

Answers (1)

Gumbo
Gumbo

Reputation: 655825

Use String.fromCharCode:

String.fromCharCode(0x0045)
String.fromCharCode(parseInt('0045', 16))

Upvotes: 12

Related Questions