Converting String to a Number in js

 Operators:-

  typeof():- The typeof() operator is used to find the type of value.

example:-

let a = 10;
let b = 1.5;
console.log(typeof(a)); 
console.log(typeof(b)); 

o/p:-

Number
Number

Converting String to a Number:-


In JavaScript, when we combine the number and string, it results in a string.

The parseInt() function accepts a string and converts it into an integer.

example:-

let a = '20';
console.log(typeof(a)); 

o/p:- string

let b = parseInt(a);
console.log(typeof(b)); 

o/p:-  number




Comments