Console Learner — An interactive JavaScript course.


1.7 Arithmetics

>>>
1 + 2 * 3
7
Arithmetic operators +, -, * and / also work as expected. Standard mathematical associativity rules (operator precedence) apply.
>>>
1.0E308 * 10
Infinity
Sometimes the numerical representation just isn't enough.
>>>
1E309 * 1E-308 * -1
-Infinity
>>>
Number.MAX_VALUE
1.7976931348623157e+308
The Number.MAX_VALUE & Number.MIN_VALUE constants provide access to the floating-point extremes.
>>>
5 / 3
1.6666666666666667
>>>
5 % 3
2
Integer math is possible by using the % (modulo) operator.
>>>
- (1 + 1)
-2
The + and - operators are also unary, meaning that they can be applied to a single value.
>>>
Math.round(1.5)
2
A bunch of common mathematical functions are available in the built-in Math object.
>>>
isFinite(NaN) || isFinite(Infinity)
false
The global isFinite, isNaN, parseInt & parseFloat built-in functions are also useful. See the Mozilla JavaScript Reference for all details.
>>>

The console allows you to interact with the course material and examples. Use the following keys:

A special logging function is also available:


Need more magic? Check out the other developer tools on this site.