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);

1st Oct 2024, 2:42 AM
Sher Agha Hewadmal
4 Respostas
+ 3
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/
1st Oct 2024, 3:37 AM
Bob_Li
Bob_Li - avatar
+ 2
let num = 50; let str = num.toString();
1st Oct 2024, 3:04 AM
Jerry Hobby
Jerry Hobby - avatar
+ 1
String interpolation in es6 str = `${num}`; typeof(str); // string
1st Oct 2024, 10:30 PM
Sharpneli
Sharpneli - avatar
2nd Oct 2024, 1:59 AM
Bob_Li
Bob_Li - avatar