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

JAVASCRIPT CONDITIONAL OPERATOR

The conditional operator, also known as the ternary operator, is used to evaluate a specified condtion and if true executes a certain statement and if false executes another statement.

The general format is a follows:

(specified condition)? if true do this:if false do this;

Example:

Say we have two members, John and Nancy. We want to only award a $1000 prize to Nancy, otherwise the prize is $0.

We declare two variables:

var member;
var prize;
Only if var member is Nancy, must var prize be $1000, otherwise it is $0. We can write it as follows:

prize=(member=='Nancy')?'$1000':'$0';

Home | Privacy Policy | Terms Of Use | Contact Us