javascript - Variable names and character encodings -
i have checked π valid javascript variable name. also, when try writing var π = math.pi in chrome console, fine.
however, when include line var π = math.pi inside .js file written sublime text 2 on mac, chrome complains:
uncaught syntaxerror: unexpected token illegal i have tried encodings utf-8, utf-16 le , utf-16 be, none work. when execute line console.log('π'), written inside sublime text 2 utf-8, chrome prints:
Ï€ how can use javascript variable name π in sublime text 2, chrome understands it?
check make sure setting <meta charset="utf-8"> in head of html or if charset different can set charset attribute on script tag:
<script src="script.js" charset="utf-8">
Comments
Post a Comment