codescracker


javascript

JavaScript if Statement



« Previous Tutorial Next Tutorial »


The if statement in JavaScript is used to execute a group of one or more than one script statements only when the given/particular condition is met.

JavaScript if Statement Example

Here is an example of if statement in JavaScript.

<!DOCTYPE HTML>
<html>
<head>
	<title>JavaScript if Statement</title>
</head>
<body>

<h1>JavaScript if statement Example</h1>
<script type="text/javascript">
	var num = 99;
	document.write("Checking the number...<br/>")
	if((num%2) != 0)
	{
		document.write(num + " is an odd number.");
	}
	document.write("<br/>Done!");
</script>

</body>
</html>

Here is the sample output of the above JavaScript if statement example:

javascript if statement

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test