Core JavaScript

If-Else Statements

If-else statements define two blocks of code. One that is executed only when a condition is true, and the other when the condition is false.

IfElseStatements.html

<!DOCTYPE html>
<html>
<head>
    <title>XoaX.net's Javascript</title>
</head>
<body>
    <script type="text/javascript" src="IfElseStatements.js"></script>
</body>
</html>

IfElseStatements.js

var dX = 3.8;

if (dX > 5) {
	document.writeln(dX + " > 5<br />");
} else {
	document.writeln(dX + " <= 5<br />");
}
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.