• Home
  • About
  • Contact
  • Speaking

Using letter Pi(π) in JavaScript

by Piotr Stapp — on javascript 09 Mar 2017

Today I was doing some math in JavaScript. I needed a simple calculation from degrees to radians. Of course, I didn't remember the formula. I copied it from Rapid Tables but I forgot to replace π char. Unexpectedly I received a normal error:

Uncaught ReferenceError: π is not defined  

What? Is Pi sign a valid variable in JavaScript?

Documentation

The official ECMA Script documentation is quite complicated. But we can simplify this to (by Mathias Bynen):

An identifier must start with $, _, or 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)”.  

This allows us to write following code from ES5

var π = Math.PI;  

Isn't this cool?


Follow @ptrstpp950

0%
Using letter Pi(π) in JavaScript
words - read.
Recent Posts:

Comments

comments powered by Disqus
Piotr Stapp Author

Piotr Stapp

Developer, engineer, craftsmen, speaker & biker. User of all useful technologies. Believe in people not papers. DevOps & automation adept. In love with web technologies. I speak here for myself only.

Previous post Discover what is inside webpack bundle You start a new project using magic tools like yo, a built-in CLI (e.g. aurelia-cli, angular-cli, react-cli, vue-cli,…
Next post Working on IISExpress with custom domain and SSL on 443 Working with IISExpress in extremely useful. But running in on custom domain and SSL on a default port (443)…
All content copyright Reset your code © 2017 • All rights reserved.
Proudly published with Ghost