Alex Alex -3 years ago 90
Javascript Question

The returned Boolean value converted to the Boolean value

Here is some code : Infinity Loop Slider Concepts, there is boolean statement, that return true or false, and than again convert it to boolean with double operator (!), the line of code:

cycle = !!(current === 0 || current > len);


So a'm interesting why autor used !!(//code), as i know !! Ņonverts the value to a logical true / false ,but the code have already return boolean value (current === 0 || current > len) // true / false.
Please explain or (!!) was unnecessary?

Answer Source

=== returns a boolean, which means current === 0 returns a boolean, > returns a boolean, which means current > len returns a boolean, which means current === 0 || current > len returns a boolean. Casting that to a boolean yet again is absolutely superfluous.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download