Switch cases use strict comparison (===). The values must be of the same type to match. A strict comparison can only be true if the operands are of the same type.
Use the switch statement to execute one of many code blocks based on a variable or expression's value. The switch expression is evaluated once. The comparison value will match either a statement value or trigger a default code block.
The switch statement is a part of JavaScript's "Conditional" Statements, which are used to perform different actions based on different conditions. Use switch to select one of many blocks of code to be executed. This is the perfect solution for long, nested if/else statements.
In answer to your question, it's === .
Take a look at ECMA 262, section 12.11, the second algorithm, 4.c.
c. If input is equal to clauseSelector as defined by the === operator, then...
http://qfox.nl/notes/110 answers your question. (This guy knows a lot about the nitty gritty of JavaScript)
Switches in Javascript use strict type checking (===). So you never have to worry about coercion, which prevents a few wtfjs :). If on the other hand you were counting on coercion, tough luck because you can't force it.
Yes, switch
"[uses] the strict comparison, ===
".
Source: switch - JavaScript | MDN
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