As reported in the title:
Why in Javascript -1 * 0 = -0
?
How I can prevent it?
I would have expected to have 0
as result.
As reported in the title:
Why in Javascript -1 * 0 = -0
?
How I can prevent it?
I would have expected to have 0
as result.
Do you have a specific reason for wanting to prevent that?
If your concern is related to the fact that you want to get 0
instead of -0
you don't need to worry about that since -0 === 0
return true
console.log(-1 * 0)
console.log(-1 * 0 === 0)
const turnItToNegative = n => -1 * n
const myNumber = turnItToNegative(0)
if (myNumber === 0) {
console.log('This is still zero, don\'t worry')
}