Numbers make it possible to work with integers of arbitrary length. They are rarely needed and are used in cases where you need to work with values outside the maximum safe integer value
Any number, even a decimal fraction with a lot of decimal places, is never quoted.
You can use four types of numeric literals: decimal, binary, octal, and hexadecimal. Since the last three are used quite rarely, we will omit their detailed description 🖊️, but the curious can get acquainted with them here.
Be careful when using leading zeros! This means you don't need to put zero before the decimal number.
0888 // 888 is treated as decimal
0777 // treated as non-strict octal (511 decimal)
Two or more integers can be used to form a new integer. There are many ways to compose a new integer. The way to compose a new number from two or more numbers is called arithmetic. In general, there are many arithmetic operations, but there are only four basic ones: addition, subtraction, multiplication and division. They are called basic, because all other actions are brought to them.
The plus sign
+ is used to express addition:
4 + 4 Answer:
– for subtraction:
7 - 6 Answer:
* represents multiplication:
3 * 4 Answer:
15 / 5 Reply:
If more than one action is performed in a line, we use - (parentheses) to separate them from each other and also to make the code📟 more readable. Let's type the following sentences into the console. The answer for each of them should consist of only one digit9️⃣:
3 * (2 + 1)
(27 + 9) / (10 - 6)
(63 / 3 ) / (6 + 1)
2 * (5 - 8 / 2) + (3 + 4)
Enter the following values into
LIVE EDITOR 👇:
An operator is a symbolic designation of some action performed with operands in an expression (For example:
The operand is some value that is processed in the program. Operands can be of any data type. The operand to the left of the operator is the left operand, the operand to the right of the operator is the right operand.
The main operator of combined assignment is the equal to
=, and it assigns the value of the right operand to the left one. That is -
x = y assigns the value to the variable 🔔
y, to the variable 🔔
You have seen many times how you assign values to variables 🔔 using mathematical operators. For example, like this:
let sum = 2 + 3 // sum value 7
And you probably did not have time to forget that at any time you can change the value of an already known variable 🔔:
Assignment with addition
+ = in order to quickly increase the value of a variable! Here are some examples:
let value = 5
value += 2 // value is now 7 (same as value = // value + 2)
value += 3 // value is now 10 (same as value = // value + 3)
value = value + value // 20 (or you can just value + = // value)
value += value // 40 (same as value = value + // value)
You already guessed that such things work with other mathematical operations, right?!
value -= 25 // value is now 15 (same as value = value - // 25)
value *= 2 // value is now 30 (same as value = // value * 2)
value /= 3 // value is now 10 (same as value = // value / 3)
value // Answer: 10
Next, check all the listed examples in
You can read more about combined assignment here
Increment and decrement
++ (increment) increases the value of its operand by one. If the value of the operand is not a number, the operator automatically converts it to a number, increments it by one, and returns the result, which is assigned back to the operand:
-- (decrement) works similarly to the increment operator, but does not increase the value of its operand, but, on the contrary, decreases it by one:
The modulo operator
% (percent) signifies the remainder of the division. The operator returns the integer remainder of dividing the left operand by the right. The return🔄 value always gets the sign of the dividend, not the divisor. It uses the built-in function⚙️ modulo, which is the integer remainder of dividing
12% 5 result
NaN% 2 results in
1% 2 result
2% 3 result
4% 2 result
5.5% 2 result
Check out all the listed examples in
LIVE EDITOR and you will immediately understand everything:
Math.round () method returns a number rounded to the nearest integer. If the fractional part of the number is greater than or equal to
0.5, the argument will be rounded to the nearest larger integer. If the fractional part of the number is less than
0.5, the argument will be rounded to the nearest lower integer.
result = Math.round (20.49) Returns 20
result = Math.round (20.5) Returns the value 21
check it yourself:
Write to Discord chat.
What arithmetic operations are called basic?
- Addition, subtraction
- Multiplication, division
- Addition, subtraction, multiplication, division
What is the correct reading of
- Assignment with addition
- Plus and equal
How is the increment written by sign (s)?
What is the sign for the remainder of the division?
What value will
Math.round return when
Math.round (20.62)is applied?
In order to understand how much you learned this lesson, take the test in the mobile application of our school on this topic or in our telegram bot.
- MDN web docs
- Integer arithmetic
Thanks goes to these wonderful people (emoji key):
🐛 🎨 🖋