Javascript Tutorial Example
Example
Javascript Array
JavaScript Boolean
JavaScript Date
JavaScript Math
JavaScript Number
JavaScript String
Javascript Tutorial
Javascript Introduction
Javascript Syntax
Javascript Enable
Javascript Location
Javascript External
Javascript Operators
Javascript Variables
Javascript Functions
Javascript Events
Javascript Statements
Javascript If
Javascript Else If
Javascript While
Javascript For Loop
Javascript Comments
Javascript Array
Javascript Alert
Javascript Confirm
Javascript Prompt
Javascript Print
Javascript Redirect
Javascript Pop Up
Javascript Date
Javascript Form
Javascript Void 0
JavaScript Comparison
JavaScript Switch
JavaScript Try Catch
JavaScript Special Text
JavaScript Throw
JavaScript Math
JavaScript RegExp
Javascript String
Javascript Strings
Javascript Length
Javascript Split
Javascript Search
Javascript Replace
Javascript IndexOf
Javascript Compare
Javascript Advanced
Javascript getElementById
Javascript innerHTML
JavaScript Browser
JavaScript Cookies
JavaScript Animation
JavaScript Image Maps
JavaScript Timing
JavaScript Create Objects
JavaScript Summary
As your JavaScript programs get more sophisticated, you will need to make use of conditional statements that allow your program to make decisions. Nearly all other programming languages use conditionals, and JavaScript is no exception.
The "If Statement" is a way to make decisions based on a variable or some other type of data. For example, you might have a variable that stores the date. With this tiny bit of information, you can easily program a small script to print out, "Today is my Birthday!" whenever the day and month were equal to your birthday.
This lesson will teach you the basics of using an "If Statement" in JavaScript.
There are two major parts to an If Statement: the conditional statement and the code to be executed.
The conditional statement is a statement that will evaluate to be either True or False. The most common type of conditional statement used checks to see if something equals a value. An example would be checking if a date equals your birthday.
Below is a segment of JavaScript code that will be executed only if the If Statement's conditional statement is true. In this simple If Statement example, we print out a message if the variable we are checking is equal to 10.
<script type="text/javascript">
<!--
var myNumber = 10;
if(myNumber == 10){
document.write("thanks you are selected 10 number");
}
//-->
</script>
This simple example created myNum and set it to 10. We then checked to see if myNumber was equal to 10 ("myNumber == 10") in the If Statement's conditional statement, evaluated to True.
Because the conditional statement was True the block of code associated with our If Statement ("document.write...") was executed, as you can see in the Display.
We already taught you how to execute code if a given condition is True, but what if you want to execute another piece of code if something is False? The answer is to use an extension to the If Statement; the Else clause.
The Else clause is executed when the conditional statement is False. Let\'s take our example from above, add an Else clause, and change the value of myNum so that our conditional statement is False.

