Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the switch statement use === or ==? [duplicate]

Does the Javascript switch statement compare strictly or by type-converting?

like image 701
danihodovic Avatar asked Mar 27 '26 05:03

danihodovic


1 Answers

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 case clause 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 matching case clause is found, the program looks for the optional default clause...

like image 94
BoltClock Avatar answered Mar 29 '26 19:03

BoltClock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!