Technical Training
JavaScript TutorialJavaScript Conditional Statements Part 1
JavaScript Conditional Statements Part 1
In this JavaScript tutorial, you will learn about the conditional statements available in JavaScript for decision making, if statement and if...else statement.
Just like any other programming language, conditional statements in JavaScript are used for decision making purpose.
The conditional statements available in JavaScript for decision making are:
- if statement
- if...else statement
- if...else if....else statement
- switch statement
NOTE: All syntax specified above must be written exactly as above since JavaScript is a case-sensitive language.
if statement:
If a programmer wants to execute certain statements only when a desired condition is satisfied or has true value then conditional if statement is used.
General syntax of if statement in JavaScript is as follows:
|
Let us see an example to understand this concept:
|
Output of the above script as produced in a HTML page is shown below:

In the above example, if block will be executed only when value of the variable is less than 30. In our example, the value of variable exforsys is 20 (which is less than 30) hence if block is executed and the output Welcome is printed.
if...else statement:
This conditional structure is used in JavaScript if a programmer wants to execute a certain block of statements if a condition is true and execute another block of statements if the condition returns false value.
General syntax of this if...else structure in a JavaScript is as follows:
|
For example
|
Output of the above script as produced in a HTML page is shown below:

In this example, if block is executed only when the value of variable exforsys is less than 30, otherwise else block will get executed, since the value of variable exforsys in our example is 40, else block is executed and the output Thank You! is printed.
JavaScript Tutorial
- JavaScript Browser Objects Part 2
- JavaScript Frame object
- JavaScript Form Object
- JavaScript FileUpload Object
- JavaScript Event Object Properties and Methods
- JavaScript Event Object
- JavaScript Elements and Embed Objects
- JavaScript Applet Objects
- JavaScript Browser Objects
- JavaScript Object Oriented Features
- JavaScript Window Object Open Method Part 2
- JavaScript Window Object Open Method
- JavaScript Window Object Timeout Methods
- JavaScript Location Object
- JavaScript Location Object Properties
- JavaScript History Object Properties and Methods
- JavaScript Document Object Methods Part II
- JavaScript Document Object Methods Part I
- JavaScript Document Object Properties
- JavaScript Document Object
- JavaScript Windows Object Properties Part II
- JavaScript Windows Object Properties Part I
- JavaScript DOM Window Object
- Working with JavaScript DOM Objects
- JavaScript Array Object Methods – Part II
- JavaScript Array Object
- JavaScript Array Object Methods – Part I
- JavaScript Boolean Object
- JavaScript OnError Event
- JavaScript Exception Handling – Part II
- JavaScript Exception Handling – Part I
- JavaScript Event Handler
- JavaScript Events Handling
- JavaScript Array Operations
- JavaScript Two Dimensional Arrays
- Passing values to JavaScript Function
- JavaScript Functions
- JavaScript Arrays
- JavaScript Iterative Structures - Part II
- JavaScript Iterative Structures - Part I
- JavaScript Math Object
- JavaScript Date Object
- JavaScript String Object
- JavaScript Objects
- JavaScript Confirm Box
- JavaScript Alert Box
- JavaScript Conditional Statements Part 2
- JavaScript Conditional Statements Part 1
- How to use JavaScript in HTML page
- JavaScript Variables
- JavaScript Features
- JavaScript Introduction







