Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the commonly used statements in JavaScript

Shulou Source: shulou.com Published: 2022-06-02 04:55:31 12月03日 Update

This article mainly introduces which sentences are commonly used in JavaScript. It is very detailed and has a certain reference value. Friends who are interested must finish it!

1.switch

Select one of a plurality of code blocks to be executed

Switch (e) {case 1: / / e for 1 execution here break; case 2: / / e for 2 execution here break; default: / / is not satisfied for execution here}

Note:

You don't have to interrupt the last case in the switch code block with break. The code block ends naturally here.

Switch case uses a strict comparison (= =), and the value must be the same as the type to match.

If JavaScript encounters a break keyword, it will jump out of the switch code block, so that the system will not continue to execute, which can improve performance.

2.While cycle

If the following conditions are not met, it will loop until the parameter "I" is not less than 10.

While (I < 10) {text + = "number is" + I; iTunes;} 3.Do/While loop

This is similar to the above, but it will be executed at least once, because it is executed first and then judged.

Do {text + = "The number is" + I; iTunes;} while (I < 10)

For-Loop can execute a block of code a specified number of times.

For/in-Loop through the properties of the object

While-Loop the specified block of code when the specified condition is true

Do/while-also loop the specified code block when the specified condition is true, but the loop executes the code block once before determining the condition

3. String conversion number

Many students will encounter string conversion numbers, the converted words can not remember, or lazy to write, then directly add a + sign in front of the variable

Like this:

Let a = "12" / / this is a string console.log (+ a) / / now converted to the number 12. These are all the contents of the article "what are the commonly used sentences in JavaScript?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Code loop number condition character string constant sentence content article same similar value key keyword interest word parameter variable classmate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker Apple Shulou Information macOS