02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School

Conditionals 2: 'switch'

Switch is another form of conditional. It can replace multiple <b>else..if</b> sections. Like the <b>if</b>, it also executes depending upon the given conditions but the syntax is much easier to read and write. Switch is slick!

Duration: 57:02

Dependency warningThis course builds on concepts from Conditionals 1 - 'if'.
Beginner Level
Beginner Level
Medium-paced Course
Medium-paced Course

Created with

Ben Fhala

Ben Fhala

Ben Fhala is the creative force and founder behind 02geek, a pioneering platform dedicated to making web development accessible to everyone. With over 18 years of experience in the industry, Ben has a deep passion for teaching and a knack for breaking down complex concepts into easy-to-understand lessons.

Conditionals 2: 'switch' Overview

What you'll learn

We have seen various methods to write if conditional depending upon number of conditions which includes if, if..else, else..if, nested..if etc. Switch can be used to replace else..if conditional statement and is used when there are multiple options to make the code simple. In this video, we will learn how to write switch and understand its importance over if conditional in various circumstances. We will also look at keywords such as break and exit, and learn the concept of ternary operation.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!

Overview

We'll look at the drawbacks and lack of flexibility of the if-else and else-if construct, and propose an alternative which is more flexible and powerful

01:59

Switch

We'll introduce you to the switch construct, explaining how it can be used to make decisions based on checking and comparisons using a single identifier

06:59

Breaking The switch Down

We'll discover and describe in detail the importance of using break statements in switch cases, and the pitfalls if we forget/choose not to do so. Let us learn about the break keyword in detial

11:06

Switch In Action: Days Of The Month

We will see a few code examples in as3 to illustrate certain programming logic which can be implemented very easily and concisely using switch constructs

13:09

What if Can't Do...

We'll see unique programming logic which is elegantly and efficiently achieved using switch constructs, but are next to impossible with if constructs

09:17

The Ternary Operation (:?)

Enhancing the readability of code and introducing efficiency for simple decision making scenarios using ternary operator ?: We will also learn the syntax for using ternary operator

07:39

The Ternarator

In this video, we will see how to use ternary operator for complex conditionals. We will compare it by if conditional and discuss the necessity for understanding the concept and its implementation in

06:53

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!