Get the App
SLTechnology News&Howtos  ›  Development  › 

What does javascript's case mean?

Shulou Source: shulou.com Published: 2022-06-02 03:36:35 09月17日 Update

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.

Tags: Code different statements conditions content actions at the same time meaning skills knowledge expressions grammar concise concise principles variables multiple that is tutorials articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux Docker Apple Shulou Tech Info