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.

	<title>JavaScript if Statement</title>

<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.");


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

javascript if statement

« Previous Tutorial Next Tutorial »