Introduction:
Number Types:
Integers
Floating Point Numbers
, or floatsSpecial Numbers Numbers
, or floats
Whole numbers
Decimal point numbers such as 1.35.
NaN, Infinity, -Infinity, e.
NaN: Not a Number. Returned if you try math on text, for example.
e: 1e9 = I billion (1 with 9 zeros); 1e-9 = minus 1 billion.
When using numbers in Javascript, they are not wrapped in "". In an [array]
, if they are wrapped in ""
they are treated not as numbers but as "strings"
. In other words, the sum of "12" + "6" will return NaN, or NotaNumber.
Expressions:
Expressions are sums. So 1+3
is an expression.
The numbers are operands
and the arithmetic operator (+-*/ etc) is an operator
.
Thus:
operand operator operand = result
Operators:
- Binary
- Unary
Need two operands
# | Type | Example | Result | Remark |
---|---|---|---|---|
+ | Addition | 10+5 | 15 | |
- | Subtraction | 10-5 | 5 | |
* | Multiplication | 10*5 | 50 | |
/ | Division | 10/5 | 2 | |
% | Modulus | 10%5 | 0 | Remainder: 10/5=2r0 |
** | Exponentiation | 10**5 | 100000 | The Power Of: 105 |
Need one operand
# | Type | Example | Result | Remark |
---|---|---|---|---|
++ | Increment | 10+* | 11 | Adds 1 |
-- | Decrement | 10-- | 9 | Subtracts 1 |
- | Unary Negation | -10 | Transforms a + into a - | |
+ | Unary Pus | =10 | Transforms a - into a + |