dangerChihuahua007
dangerChihuahua007

Reputation: 20915

How come this alert of a unicode character is not successful?

I tried to make an alert popup with "A" with:

var a = \u0041;
alert(a);​

jsfiddle

However, I get an error in Chrome Console: Uncaught ReferenceError: A is not defined.

What does that mean? I don't have a variable called A anywhere.

Upvotes: 3

Views: 1612

Answers (1)

nbrooks
nbrooks

Reputation: 18233

\u0041 is the unicode for capital letter A. The interpreter translates it as is, not assuming that it is a string.

To alert the value rather than looking for a variable with that name, do alert("\u0041")

Following your code style, the modified code would look like this:

var a = "\u0041";
alert(a);

Upvotes: 7

Related Questions