Implicitly convert boolean to numbers in javascript

Implicitly convert boolean to numbers in javascript
0

#1

I think that we should avoid this all together and just use the explicit method
Number(false) instead.

am I right?


#2

Well…coercion is a feature of JS, but yes I suppose that’s a good practice. I use Number() for strings to numbers on a regular basis.


#3

thank you.

i wont try to ignore how implicit coercion works but at the same time i wont use it exclusively just to confuse myself.

:stuck_out_tongue:


#4

Just as a neat little trick, you can also explicitly convert using + in front of a String.

var five = '5';
five // '5'
+five  // 5
five + five  // '55'
+five + +five  // 10

#5

thanks for the tip!!!