Implicitly convert boolean to numbers in javascript

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

am I right?

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.

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:

1 Like

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
1 Like

thanks for the tip!!!