4 minute(s) read
Published on: Jun 04, 2021
Updated on: Dec 14, 2021
As you know, there are different programming languages that of them can help programmers a lot, these languages are being used to enter different variables, each of which can have values, and it is important to learn the basics of importing each one through different codes, as well as checking whether the imported codes are executed correctly or not.
What is JS?
In this language, numbers can be written in decimal or normal format, now note the following example where both types of numbers are given.
To write numbers that are extra small or extra-large, you can use the exponent, which we will give an example in the following.
Adding Numbers and Strings:
In this section, you can see different cases. For example, two numbers may have been added to each other or two strings. Still, in general, the point that needs to be mentioned is that if you enter the code numerically in several lines, they will be added together, but if you do the same thing as a string, the strings will only join together.
If you add two numbers, then it is clear that the result you will see is a number at the end. To understand it better, pay attention to the following example.
The next thing that is likely to be done is to enter two strings, in which case the result will be clear, and in the end, what you will see as the result will be the merging of the two strings, for this case, there is an example below and the result of which is 4060.
Now imagine adding a number and a string, in which case the result will be as a string, and the two lines will join together. The result of the example which is mentioned below is also 4060.
* / - operations:
In these three operations, JS tries to provide numerical results because numerical data is added as a string. To understand it better, an example is given for each operation.
- In connection with the division operation:
- In connection with the * operation:
- In connection with the - operation:
Not a Number:
Infinity (or -Infinity) is displayed when the result is outside the largest number defined in this language.
Number Methods help you work with numbers better, and we will discuss some available methods.
- toString () Method:
The toString () method returns a number as a string. We suggest you pay attention to the following example to understand it better.
- toExponential () Method:
To write a number using exponential notation, you can use this method, which shows the string as a number with its help.
- toFixed () Method:
In this method, you can specify the number of decimal digits when there is a decimal number.
- toPrecision () Method:
With the help of this method, the length of a number can be determined.
- valueOf () Method:
In this method, a number returns as a number.