The below are the methods to convert a Integer to String in JS
The methods are arranged in the decreasing order of performance.
(The performance test results are given by @DarckBlezzer in his answer)
var num = 1
Method 1:
num = `${num}`
Method 2:
num = num + ''
Method 3:
num = String(num)
Method 4:
num = num.toString()
Note: You can't directly call toString()
on a number. 2.toString()
will throw Uncaught SyntaxError: Invalid or unexpected token
.