ThatDarnPat
ThatDarnPat

Reputation: 80

Why is ∆ not a valid identifier in JavaScript?

According to this, JavaScript allows Unicode characters as identifiers. However, this is how Node handles it.

  > var ∆ = 6;
  > ...

I've also put it in the identifier validator, and it agrees that "∆" shouldn't be allowed.

I suppose my question is "What's so special about ∆?"

Upvotes: 2

Views: 883

Answers (2)

SLaks
SLaks

Reputation: 887837

That isn't U+0394 GREEK CAPITAL LETTER DELTA; it's U+2206 INCREMENT, which is a Math Symbol, not a Letter.

Upvotes: 7

Pointy
Pointy

Reputation: 413866

JavaScript identifiers can contain any "Unicode Letter", which means

any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”.

Now, what you can do is this:

var \u0394 = 0;

and 0394 is the Unicode value for ∆. Clearly, that's not quite as satisfying, but it is syntactically OK.

edit — as usual SLaks is correct; you can in fact do this:

var Δ = 0;

when you've got the right version of Δ. (In my current font the math version is prettier.)

Upvotes: 2

Related Questions