Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable names and character encodings

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?

like image 358
Randomblue Avatar asked Jun 04 '12 20:06

Randomblue


1 Answers

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">
like image 113
Trevor Avatar answered Sep 30 '22 15:09

Trevor