How to use If...Else to implement conditional statements in JavaScript
This article mainly introduces JavaScript how to use If...Else to achieve conditional statements, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
JavaScript conditional statement
Conditional statements are used to perform different actions based on different conditions.
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...else if....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.
If the time is earlier than 20:00, you will be greeted "Good day".
Click here.
Function myFunction () {var x = ""; var time=new Date () .getHours (); if (time