Does the Javascript switch statement compare strictly or by type-converting?
It only uses strict comparison. In particular, it never falls back to type coercion even when no strict matches are found — it will immediately skip to the default clause, if any. From MDN:
The program first looks for a
caseclause whose expression evaluates to the same value as the input expression (using strict comparison,===) and then transfers control to that clause, executing the associated statements. If no matchingcaseclause is found, the program looks for the optionaldefaultclause...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With