How to convert a number to string via unary operator in Javascript?

Viewed 961

In Javascript, to convert strings to numbers we can do:

var str = "1" // "1" as string 
var num = +str  //  1  as number 

Which operator I can use for doing the same in reverse similar to number.toString()? ie converting a number to a string

var num = 1             //  1  as a number 
var str = (operator)num // "1" as a string 
1 Answers

There is no "bitwise operator" that returns a string, also the "unary plus operator" is not bitwise. The closest versions would be:

 "" + 12
 `${12}`
Related