The ==
operator in JavaScript converts its operands into a common type before checking for equality (that's why it is recommended always to use the ===
operator, which respects the types).
In your case the common type is number
, so the each given array is converted into a number. For a single element array the conversion into a number results in the single element (converted to a number).
The parameter [2]
equals the number 2, so return false
.
[3]
on the other hand does neither equal 0, 1, or 2, so return true
.
See also https://www.w3schools.com/js/js_type_conversion.asp for more examples.