+ 1
What does + do here ?
In a challenge, + is used but I don't know what's it is doing. I was something like this : let a = 0.3; console.log(a.toFixed(2)) // 0.30 console.log(+a.toFixed(2)) // 0.3 Is that a syntax commonly used, to put this + on its own ? What is it doing exactly? Why does it remove one zero ? https://code.sololearn.com/WQrtzOS2JS2b/?ref=app
2 Answers
+ 2
+ here is the unary plus operator, which is often used in evaluating non-number values.
(+"304" === 304) // True
In your case it return a new number, with a 0 digit removed by JS floating point math, since the value returned by toFixed() is a string.
+ 2
+ here is equivalent to function Number
console.log(Number(a.toFixed(2)))
https://code.sololearn.com/W4MxUr156k7k/?ref=app