Home >Web Front-end >JS Tutorial >Analysis of javascript switch usage precautions_javascript skills
This article analyzes the usage notes of switch in javascript with examples. Share it with everyone for your reference. The specific analysis is as follows:
Let’s look at the following code first:
<script> var t_jb51_net = 65; switch (t_jb51_net) { case '65': alert("字符串65。jb51.net"); break; } </script>
You will find that no dialog box pops up and the alert is not executed.
Cause analysis:
What needs to be made clear here is that switch uses the congruent sign "===" when making judgments. When comparing congruent signs, it first checks whether the data types are the same, and here, t_jb51_net is of Number type. , and '65' is String.
The following code will pop up the dialog box:
<script> var t_jb51_net = 65; switch (t_jb51_net) { case 65: alert("数字65。jb51.net"); break; } </script>
I hope this article will be helpful to everyone’s JavaScript programming design.