Javascript Convert -0 to string correctly
5 answers
If Node.js (or npm is available ¹) util.inspectdoes this:
> util.inspect(-0)
'-0'
If not, you can make a function:
const numberToString = x =>
Object.is(x, -0) ?
'-0' :
String(x);
Replace the condition x === 0 && 1 / x === -Infinityif you do not Object.is.
¹ I have not read this source of packages, and it may be updated in the future; look at it before installation!
+3