When using the ==
operator, JavaScript performs type coercion to try to compare the two values. For example, 5
== '5'
is true
because JavaScript will convert the string '5'
to the number 5
before making the comparison. However, it's generally better to use the ===
operator when comparing values to avoid unexpected results due to type coercion.