4 minute(s) read
Published on: Jun 04, 2021
Updated on: Dec 14, 2021
As you know, there are different programming languages that each one of them can help programmers a lot, these languages are being used in order to enter different variables, and 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, it is possible for numbers to be written in decimal or normal format, now note the following example where both types of numbers are given.
In order to write numbers that are extra small or extra large, you can use the exponent, which we are going to give an example in the following.
Adding Numbers and Strings:
In this section, you can see different cases, for example, it is possible that two numbers have been added to each other or two strings, but 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 at the end the result you will see is a number, in order 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 3 operations, JS tries to provide numerical result in a case that numerical data is added as a string, in order 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) are displayed when the result is outside the largest number defined in this language.
Number Methods help you work with numbers better, which we are going to discuss a number of available methods.
- toString () Method:
The toString () method returns a number as a string, to understand it better, we suggest you pay attention to the following example.
- toExponential () Method:
In order to write a number using exponential notation, you can use this method, which shows the string as a number with the help of it.
- 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.