01. Control flow

Control flow allows you to direct the flow of code depending on the conditions which are given. Here are the main operators used in comparison evaluations.

Comparison operators

<
Less than.
>
Greater than.
>=
Greater than or equal to.
<=
Less than or equal to.
4 > 10   // false
'hi' > 'hello'    // true, checks if greater alphabetically
4 >= 3   // true

Conditionals

==
Equal to - doesn't have to be the same type.
===
Strict equal to - must be the same type.
!=
Not equal to.

The difference between the first two conditionals can be show by a simple example:

3 == '3' // true
3 === '3' // false, must be of same type
3 != 3    // false

Logical operators

The logical operators AND or OR allow you to group two evaluations together. An AND evaluates to true only if both sides of the expression are true, while an OR evaluates to true if either side is true.

To get the opposite of an evaluation, use the exclamation mark (!). This will turn a false into true and vice versa.

&&
AND operator
||
OR operators
!
NOT operator
!true;            // false
! (3 > 3)         // true
4 < 3 && 2 < 5;   // true
true || false     // true

Build modern and responsive webpages

HTML & CSS

Build modern and responsive webpages Try Front-end

This book teaches HTML as if it's for anyone - hobbyists, students, and professionals - and it's full-color throughout. It utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging. You can progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure.

$ Check price
29.9929.99Amazon 4.5 logo(926+ reviews)

More Front-end resources

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources

Ad