+ 1
Can we change the Datatype of variable in javascript .
Ex : x= "1"; Here x is string. Can " 1" String convert into Number 1.
5 Réponses
+ 6
Yes why not
Just use the parseInt function
Var x ="1";
Var num=parseInt (x);
//Now you can do arithmetical operations with it.
You can also convert it into float by using parsefloat function
+ 3
Yes why not use perseInt() function
+ 3
Hello Ashu. Sure you can :))
const x = "1"; // here 1 is a string
const num = Number(x); // now 1 becomes a number
console.log(num);
Use the Number function to make a string-number to number!
0
Ayush. Ks
Arb rahim badsa
I have try both
1. Number(x)
2. perselnt()
it work
Thanks.
0
Thanks Shreyansh bro.