3

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?

tirithen
  • 3,219
  • 11
  • 41
  • 65
  • 1
    Why don't you use `String.fromCharCode(n)`? See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/fromCharCode – Elian Ebbing Mar 30 '11 at 20:59

1 Answers1

11

Use String.fromCharCode:

String.fromCharCode(0x0045)
String.fromCharCode(parseInt('0045', 16))
Gumbo
  • 643,351
  • 109
  • 780
  • 844