JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods

IF STATEMENTS IN JAVASCRIPT

You can use an if statement in your javascript programming to test a condition and only if it tests true, will certain code that you specify between the braces execute.

The general format of the if statement is:

if(certain condition)

{

execute this code;

}

Example:

var username="dolly24";

if(username=='dolly24')

{

alert("hello " + username);

}

Above, what we are saying is that only if the username is dolly24, will an alert message display with Hello dolly24 (code between the curly braces). Therefore, if the username is anything else besides dolly24, nothing happens. In the above example, Hello dolly24 will display as we have declared the username to be dolly24 in the first line of the code.

Home | Privacy Policy | Terms Of Use | Contact Us