Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To convert string to number in javascript, use + unary plus oprator it’s one of the fastest way to convert string to int. let’s take a example

The unary plus operator (+) precedes its operand and evaluates to its operand but attempts to convert it into a number, if it isn’t already.

In the following example, we can able to convert string to number, float or any negative number using + unary plus oprator.

// Int 
console.log(+"90") // 90

// Float
console.log(+"90.90") // 90.9

// Negative Number
console.log(+"-90") // -90

Today, I’m going to show you How do i convert string to number in javascript, as above mentioned here, I’m going to use + unary plus oprator to convert string to number.

Let’s start today’s tutorial how do you convert string to number in javascript?

In this example, we will do

  1. Convert string to integer
  2. Convert string to decimal
  3. Convert string to negative number
// Convert string to integer
let first = "100";
first = +first;
console.log(first); // 100

// Convert string to decimal
let second = "25.386";
second = +second;
console.log(second); // 25.386

// Convert string to integer
let third = "-100";
third = +third;
console.log(third); // -100

In the above exampls, we have taken multiple string number types examples to convert it into numbers, Let’s check the output.

JavaScript, convert string to number in javascript example
JavaScript, convert string to number in javascript example

I hope it’s help you, All the best 👍.