I have checked that π
is valid for a JavaScript variable name. Also, when I try writing var π = Math.PI
in the Chrome console, all is fine.
However, when I include the line var π = Math.PI
inside a .js
file written with Sublime Text 2 on a Mac, Chrome complains:
Uncaught SyntaxError: Unexpected token ILLEGAL
I have tried the encodings UTF-8, UTF-16 LE and UTF-16 BE, but none work. When I execute the line console.log('π')
, written inside Sublime Text 2 with UTF-8, Chrome prints:
Ï€
How can I use the JavaScript variable name π
in Sublime Text 2, so that Chrome understands it?
Check to make sure you are setting a <meta charset="utf-8">
in the head of your html or if the charset is different you can set the charset attribute on your script tag:
<script src="script.js" charset="utf-8">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With