Get the App
SLTechnology News&Howtos  ›  Development  › 

What is a conditional statement in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 03:32:21 09月18日 Update

This article mainly introduces what is a conditional sentence in JavaScript, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.

JavaScript if...Else statement

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

Conditional statement

Usually when writing code, you always need to perform different actions for different decisions. You can use conditional statements in your code to accomplish this task.

In JavaScript, we can use the following conditional statement:

If statement-use this statement to execute code only if the specified condition is true

If...else statement-executes code when the condition is true and other code when the condition is false

If...elseif....else statement-use this statement to select one of multiple code blocks to execute

Switch statement-use this statement to select one of multiple code blocks to execute

If statement

This statement executes code only if the specified condition is true.

Grammar

If (condition)

If (condition)

{

Code executed when the condition is true

}

Please use lowercase if. Using uppercase letters (IF) generates a JavaScript error!

Example

When the time is less than 20: 00:00, a greeting "Goodday" is generated:

If (time

Tags: Statement condition code different article one action only multiple generate select value task interest at the same time uppercase uppercase letter instance lowercase Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple NVidia vpn Redmi