This article analyzes the precautions for using switch in JavaScript. Share it for your reference. The specific analysis is as follows:
Let’s take a look at the following code:
<script>var t_jb51_net = 65;switch (t_jb51_net) {case '65':alert("String 65.VeVB.COM");break;}</script>You will find that no dialog box pops up and alert is not executed.
Cause analysis:
It should be clear here that when the switch judges, the total equal sign "===" is used. When comparing the total equal sign, it first depends on whether the data type is the same. Here, t_jb51_net is the Number type, and '65' is the String.
The following code will pop up:
<script>var t_jb51_net = 65;switch (t_jb51_net) {case 65:alert("number 65.VeVB.COM");break;}</script>I hope this article will be helpful to everyone's JavaScript programming.