Home >Web Front-end >JS Tutorial >Javascript basic tutorial if conditional statement_basic knowledge

Javascript basic tutorial if conditional statement_basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:19:351447browse

if is one of the commonly used syntaxes, its format is as follows

if(coditon) statement1 (else statement2)

Among them, coditon can be any expression, even a real Boolean value, because JavaScript will automatically convert it into a Boolean value.

If the condition execution result is true, statement1 will be executed. If the condition is false, the execution result statment2 will be executed. (If statement2 exists, else is not necessary.)

Each conditional statement can be a single line of code or a block of code. The following is a simple example

Copy code The code is as follows:

var iNumber = Number(prompt("Please enter a number between 5 and 100"));
If (isNaN(iNumber))
Document.write("Please confirm the number you entered.");
else if(iNumber > 100 || iNumber < 5 )
Document.write("The value you entered is not within the range");
else
Document.write("The value you entered is " iNumber);
Statement:
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