How to use the Number() function In Javascript
The Number function is used to convert the parameter to the number type.
Example:
Javascript
function convertStoI() { const a = "100" ; const b = Number(a); console.log( typeof (b)); const d = "3 11 43" * 1; console.log( typeof (d)); } convertStoI(); |
number number
How to convert a string into a integer without using parseInt() function in JavaScript ?
In JavaScript, there is a simple function parseInt() to convert a string to an integer. In order to know more about the function, you can refer to this. In this article, we will learn how to convert the string to an integer without using the parseInt() function.
Advantage of parseInt() over this method. The parseInt() function converts the number which is present in any base to base 10 which is not possible using the method discusses above.
Below are the following methods:
- Using coercion
- Using the Number() function
- Using the unary + operator
- Using Math floor() Method
- Using Math.ceil( ) function