int to string in javascript

To convert a number to a string in JavaScript, you can use the toString() method. This method can be called on any number and will return the number as a string.

index.tsx
let num = 123;
let str = num.toString();
console.log(typeof str); // "string"
console.log(str); // "123"
105 chars
5 lines

Alternatively, you can also use the String() constructor to convert a number to a string.

index.tsx
let num = 456;
let str = String(num);
console.log(typeof str); // "string"
console.log(str); // "456"
102 chars
5 lines

Both methods will produce the same result, so use whichever one you find more readable.

gistlibby LogSnag