Number
An integer number.
A Number is an integer such as 42 or -42. More precisely, a Number is a signed 32-bit integer (two’s complement).
Declare a number variable
You can assign a number to a variable:
let num = 42;
Arithmetic operators
The following arithmetic operators work on numbers and return a Number:
- addition:
1 + 3 - subtraction:
1 - 3 - multiplication:
3 * 2 - integer division:
7 / 3 - modulo is available through the math library
Relational operators
The following relational operators work on numbers and return a Boolean:
- equality:
(3 + 1) = 4 - inequality:
3 != 4 - less or equal than:
3 <= 4 - less than:
3 < 4 - greater or equal than :
4 >= 3 - greater than:
4 > 3
Functions that return a number
Some functions return a number, which you can store in a variable.
let abs = Math.abs(-42);
Math functions
The math library includes math related functions. For example, the min function returns the minimum value of two input parameters x and y:
let lowest = Math.min(-42, 1000);