JavaScript Condition Statement If... Else

Source: Internet
Author: User

When writing code, you often need to perform different behaviors according to different conditions. You can use conditional statements in the code to complete this task.

In JavaScript, we can use the following conditional statements:

If statement
Run the code when a specified condition is set.
If... else statement
Execute the code when the specified condition is set. If the condition is not set, execute another code.
If... else statement
You can use this statement to execute one of several block codes.
Switch statement
You can use this statement to execute one of several block codes.

If statement

 

<Script type = "text/javascript"> var d = new Date () var time = d. getHours () if (time <10) {document. write ("Good morning")} </Script>

This example demonstrates the If statement.

If the browser time is less than 10, you will be asked "good morning ".


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.