0
How to convert the below value to string
Code to convert the value into a string and check the data type let num = 50; let str = (num); alert( str);
4 Respuestas
+ 4
Sher Agha Hewadmal
javascript have implicit type conversion.
so you can just pass the number to alert without the need to convert it to string
let num = 50;
alert(num);
or
alert(42);
but yes, if necessary, the toString() method is one way to do it.
here are other ways:
https://www.geeksforgeeks.org/convert-a-number-to-a-string-in-javascript/
+ 3
let num = 50;
let str = num.toString();
+ 3
conversely, ways to convert string to number:
https://dev.to/sanchithasr/7-ways-to-convert-a-string-to-number-in-javascript-4l
+ 2
String interpolation in es6
str = `${num}`;
typeof(str); // string