Languages

JavaScript - what operator (== or ===) is used by switch statement to compare?

8 points
Asked by:
cory
1756

As in the question title: What operator (== or ===) is used by switch statement to compare?

Is it safe to compare different objects using switch statement?

What about?:

 

1 answer
4 points
Answered by:
Root-ssh
178290

The switch statement compares variables by values and its types, so it behaves like === operator and is safe when compare different objects.

e.g. 1:

Expected output:

 

e.g. 2:

Expected output:

 

e.g. 3:

Expected output:

 

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join