Home > Web Front-end > JS Tutorial > body text

Analysis of javascript switch usage precautions_javascript skills

WBOY
Release: 2016-05-16 16:16:13
Original
1487 people have browsed it

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>
Copy after login

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>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template