Image for post

Being the language that powers the web, JavaScript is not what it used to be when it first came out. It is so much better. So it makes sense that there is so much to learn.

As a front end developer, learning JavaScript is daunting but crucial. And if you are anything like me, you don’t know where to go, where to start. Thousands of resources to choose from which just makes us anxious and not learn anything. We get stuck in tutorial hell.

Here is something that helped me get better at the JavaScript numbers. Hope it helps you too. If you want to know more about JavaScript functions , strings, or arrays here are the quick and simple articles for you.

So without further delaying, let’s dive in. Keep in mind, all the number methods return a new value, without changing the original variable.


1. Tostring

The toString() method is what it sounds, returns the number as a string. However, if you provide a parameter, such as 2, 8, or 16 it will return binary, octal or hexadecimal value respectively.

const num = 123;

num.toString();
// "123"
(100 + 44).toString();
// "144"

2. Toexponential

The toExponential() method returns a string, with a number rounded and written using exponential notation. The parameter is optional. It is an integer between 0 and 20 representing the number of digits in the notation after the decimal point. If nothing is provided, it is set to as many digits as necessary to represent the value.

const num = 3.414;

num.toExponential(2);
//3.414e+0

#data-science #freelancing #startup #javascript #programming

8 JavaScript Number Methods as Simple as Possible
1.15 GEEK