Advanced Java and Web Technologies for JNTUK
Blog providing beginner tutorials on different web technologies like HTML, CSS, Javascript, PHP, MYSQL, XML, Java Beans, Servlets, JSP and AJAX

23/02/2014 Categories: Javascript. No Comments on Control Statements in Javascript

Statements that are used to control the flow of execution in a script are known as control statements. Control statements are used along with compound statements (a set of statements enclosed in braces). Local variables are not allowed in a control construct (control statement + single/compound statement). Even though a variable is declared within a control construct, it is treated as a global variable.


Control Expressions

The expressions upon which the flow of control depends are known as control expressions. These include primitive values, relational expressions and compound expressions. The result of evaluating a control expression is always a Boolean value either true or false.


Selection Statements

Statements which are used to execute a set of statements based on a condition are known as selection statements. In JavaScript selection statements are: if, if-else and switch.

Syntax for an if statement is shown below:

Syntax for an if-else statement is shown below:

Syntax of a switch statement is given below:

The expression and labels in a switch statement can be either numbers, strings or Boolean values.


Loop Statements

Statements which are used to execute a set of statements repeatedly based on a condition are known as loop statements or iteration statements. Loop statements supported by JavaScript are while, do-while, for and for-in.

Syntax of while loop is given below:

Syntax for do-while loop is given below:

In a do-while statement condition is evaluated after the body of the loop is executed. So, the difference between while and do-while is, unlike in while loop, the body of the loop is guaranteed to be executed at least once in a do-while loop.

Syntax of a for loop is given below:

JavaScript provides another loop statement to work with objects which is known as a for-in loop. It’s syntax is given below:


Suryateja Pericherla

Suryateja Pericherla

Hello, I am Suryateja Pericherla working as an Asst. Professor in CSE department at Vishnu Institute of Technology. I write articles to share my knowledge and make people knowledgeable regarding certain topics.
Suryateja Pericherla

Latest posts by Suryateja Pericherla (see all)

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Scroll Up
Thank you for visiting! If you like this website do share with your friends by clicking on the social icons available on the left hand side.

As the domain name is quite large to remember, use this short domain to visit this site. Short domain: