Home > Web Front-end > Front-end Q&A > What judgment structures does JavaScript have?

What judgment structures does JavaScript have?

青灯夜游
Release: 2021-11-08 15:02:42
Original
1318 people have browsed it

Judgment structure: 1. if conditional branch structure, including if, "if else", "if else if ...", "if else if ... else" statements; 2. "switch case" conditional branch structure; 3. Ternary operation structure, syntax "Condition? Expression 1: Expression 2".

What judgment structures does JavaScript have?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

The branch structure is our common judgment structure, which determines whether to execute certain code programs based on the conditions set by the user. Below, Xiaoqian will introduce to you three common branch structure syntaxes.

IF conditional branch structure

if statement

Determine whether to execute the code through an if statementa

Syntax: if (condition) {code to be executed}

Determine whether the code inside {} is executed by whether the condition in () is true
What judgment structures does JavaScript have?

if else statement

Use the if condition to determine which code in {} to execute

Syntax: if (condition) {Execute when the condition is true} else { Executed when the condition is false}

One of the two codes within {} must be executed
What judgment structures does JavaScript have?

if else if ... statement

You can set multiple conditions for judgment through if and else if

Syntax: if (condition 1) {execute when condition 1 is true} else if (condition 2) {condition 2 is true executed}

If the first condition is true, then the content in the following {} will be executed

If the first condition is false, then the second condition will be judged conditions, and so on

For multiple {}, only one will be executed. Once one condition is true, the following conditions will no longer be judged
What judgment structures does JavaScript have?

if else if ... else statement

is basically the same as the previous if else if ..., except that when all conditions are not met, the {} after the last else is executed
What judgment structures does JavaScript have?

SWITCH conditional branch structure

is also a type of conditional judgment statement, which is a judgment on a certain variable

Syntax:
What judgment structures does JavaScript have?

Use when you want to judge that a certain variable is equal to a certain value

Example: Display the day of the week based on the number given by the variable
What judgment structures does JavaScript have?

Ternary operation (expanded)

Ternary operation is to use two symbols to form a statement

Ternary operation is just a shorthand form of if else statement

Grammar: Condition? Condition Execute when the condition is true: Execute when the condition is false

What judgment structures does JavaScript have?

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What judgment structures does JavaScript have?. For more information, please follow other related articles on the PHP Chinese website!

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