|
| 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.
|
|