Posted in All Posts, Semester 2

JavaScript Basics – Flow Control Statements

Flow Control Statements are basically statements with conditions that check for a particular condition defined by the user and pass control accordingly.

if-else

if-else is the most common and widely used flow control statement.
Below is an example for you to understand.

Try It Yourself

switch-case

switch-case is used when multiple values for a single value are expected, it is a statement to overcome the only limitation of if-else statement, i.e. to handle a large number of values in a single variable.
You should always add a break statement after every case so that only that particular case block is executed.
Below is an example for the same.

Try It Yourself

Conditional Operator

It is also called as Ternary Operator as it needs three operands to operate.

Example

Try It Yourself

We hope that you found this article to be helpful.
Please share your thoughts in the Comments Section.

If you liked this article, then please like our Facebook page.

Suggested Reading

Comment your thoughts