Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does javascript's case mean?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you what javascript's case refers to. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

In JavaScript, case means to judge a condition and is often used with switch statements to perform different actions based on different conditions. The syntax is "switch (n) {case1: execute code block 1 break; default: code that is not executed at the same time as case1}".

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

What does javascript's case mean?

Switch statements are used to perform different actions based on different conditions.

JavaScript switch statement

Use the switch statement to select one of the multiple blocks of code to execute.

Grammar

Switch (n) {case 1: execute Code Block 1 break; case 2: execute Code Block 2 break; default: code not executed at the same time as case 1 and case 2}

How it works: first set the expression n (usually a variable). The value of the expression is then compared to the value of each case in the structure. If there is a match, the block of code associated with the case is executed. Use break to prevent the code from automatically running to the next case.

Examples are as follows:

Var day;switch (new Date (). GetDay ()) {case 0: day = "Sunday"; break; case 1: day = "Monday"; break; case 2: day = "Tuesday"; break; case 3: day = "Wednesday"; break; case 4: day = "Thursday"; break; case 5: day = "Friday"; break; case 6: day = "Saturday" } document.getElementById ("demo") [xss_clean] = "Today is" + day

Output result:

The above is what javascript's case refers to. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report