0% found this document useful (0 votes)
3 views

Conditional Logic and Control Flow Slides

Uploaded by

fbv2206
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Conditional Logic and Control Flow Slides

Uploaded by

fbv2206
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Conditional Logic and

Control Flow

David Tucker
CTO Consultant

@_davidtucker_ | davidtucker.net
index.js

// Example 1
let example1 = (10 > 4);
Comparison console.log(example1); // Output: true
Operators
// Example 2
let example2 = (5 >= 5);
console.log(example2); // Output: true
index.js

// Example 3
let example3 = ("Hello" === "Hi");
Equality console.log(example3); // Output: false
Operators
// Example 4
let example4 = (4 !== 7);
console.log(example4); // Output: true
index.js

// Using Conditionals
let badgeColor;
if (numYearsService < 5) badgeColor = "blue";
if (numYearsService < 5) {
badgeColor = "blue";
Using } else if (numYearsService < 10) {
badgeColor = "yellow";
Conditionals } else if (numYearsService < 15) {
badgeColor = "red";
} else if (numYearsService < 20) {
badgeColor = "purple";
} else {
badgeColor = "silver";
}
Mathematical Operators
Assignment Operators
Increment and Decrement Operators
If used prefix, with operator before operand (for example,
++x), the increment operator increments and returns the
value after incrementing.
If used postfix, with operator after operand (for example,
x++), the increment operator increments and returns the
value before incrementing.

MDN Web Docs


Comparison Operators
Standard and Strict Equality
In JavaScript, there are two different sets of
equality operators. The == and != operators are
the standard equality operators. The === and !==
are the strict equality operators. The latter
requires that both the value and the type match.
Always use strict equality
operators unless you fully
understand the different
behavior of the standard
equality operators.
Falsy Values
Falsy Values
A falsy (sometimes written falsey) value is a value that is
considered false when encountered in a Boolean context.
JavaScript uses type conversion to coerce any value to a
Boolean in contexts that require it, such as conditionals
and loops.

MDN Web Docs


Conditional Logic
Switch Statement
Switch Statement
The switch statement evaluates an expression, matching
the expression's value against a series of case clauses,
and executes statements after the first case clause with a
matching value, until a break statement is encountered.
The default clause of a switch statement will be jumped
to if no case matches the expression's value.

MDN Web Docs


Working with the Exercise Files
Demo
Reviewing the organization of the exercise
files
Installing a third-party module with npm
Configuring VS Code to debug in the
integrated terminal
Implementing User Input Validation
Demo
Creating a command line application to add
an employee to the directory
Utilizing conditional logic to validate user
input against specific rules

You might also like