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

Can javascript use if statement

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

Share

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

This article will explain in detail whether the if sentence can be used in javascript. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

If statements can be used in javascript. The if statement is the simplest conditional judgment statement in JavaScript, with the syntax "if (conditional expression) {/ / the code to be executed;}"; when the conditional expression is established, that is, the result is a Boolean true, the code in "{}" is executed.

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

If statements can be used in javascript.

The if statement is the simplest conditional judgment statement in JavaScript. The syntax format is as follows:

If (conditional expression) {/ / Code to be executed;}

When the conditional expression holds, that is, the result is a Boolean value of true, the code in {} is executed.

Example:

Var age = 20; if (age > = 18) {/ / if the result of age > = 18 is true, execute the code alert ("adult") in {} below;}

Output result:

In javascript, in addition to the simplest if statement, there are two forms of upgrade:

If else statement

If else if else statement

The if else statement can specify not only the code to execute when the expression is established, but also the code to be executed when the expression is not valid. The syntax format is as follows:

If (conditional expression) {/ / Code to be executed when an expression is valid} else {/ / Code to be executed when an expression is not valid

Multiple conditional expressions are allowed to be defined in the if else if else statement, and the corresponding code is executed according to the result of the expression. The syntax format is as follows:

Code executed if if (conditional expression 1) {/ / conditional expression 1 is true} else if (conditional expression 2) {/ / code executed when conditional expression 2 is true. Code to execute if else if (conditional expression N) {/ / conditional expression N is true} else {/ / code to be executed if all conditional expressions are false

Tip: during the execution of the if else if else statement, when it encounters a valid conditional expression, it will immediately execute the code in the following {}, and then exit the entire if else if else statement. If there is a valid conditional expression in the subsequent code, it will not be executed.

This is the end of the article on "can javascript use if sentences". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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