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

Aching back from coding all day?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources

Build modern and responsive webpages

High Performance Web Sites

Build modern and responsive webpages Try Front-end

Want your web site to display more quickly? This book presents 14 specific rules that will cut 25% to 50% off response time when users request a page. Author Steve Souders, in his job as Chief Performance Yahoo!, collected these best practices while optimizing some of the most-visited pages on the Web.

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

More Front-end resources

Ad