Javascript
JavaScript Fundamentals -- Strings, Numbers, & Dates

Working with Numbers

PRO
Outline

In JavaScript, just like many other programming languages, you can perform math operations on numbers and variables that store numbers. You can do addition, subtraction, multiplication, division etc. We aren't covering those more basic operations in this course, but did want to cover a helpful object called the Math object. The Math object is built into JavaScript and can be used anywhere in your program. You just need to type Math. and then you have access to some variables, such as the value of pi, and some methods, such as the ability to raise one number to the power of a second number. Here's an example of finding the circumference of a circle using the value of pi from the Math object.

// The circumference of a circle is 2 * π * r
const circumference = 2 * Math.PI * 4;

There are a lot of ways that you can use the Math object. Click here to visit the reference page and see all the things you can do with it.

 

I finished! On to the next chapter