












































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













































During the last lecture we had a discussion on Data Types, Variables & Operators
Variables
Declaring Variables
Although JavaScript allows variable declaration, it does not require it - except in the case when we want to declare a variable being local (more on local variables later in the course!)
JavaScript Operators
JavaScript has numerous operators, classified in many categories. We will look at only a few of them belonging to the following categories:
comments let
the code speak
for itself!
Today’s Lecture: Flow Control & Loops
Flow Control
JavaScript Flow Control Structures
if … else
switch
if: Example 1
if ( day == “Sunday” ) bhola = “Cool” ;
Set the value of the variable ‘bhola to ‘Cool’ if the ‘day’ is equal to ‘Sunday’ 14
The condition enclosed in parentheses (^) semicolon
if: Example 2
if ( day == “Sunday” ) { bhola = “Cool” ; mood = “Great” ; clothing = “Casual” ; }
Set the value of the variable ‘bhola to ‘Cool’, ‘mood’ to ‘Great’, and ‘clothing’ to ‘casual’ if the ‘day’ is equal to ‘Sunday’
16
These curly braces group the multiple statements into a single compound statement
if: Example 2
if ( day == “Sunday” ) { bhola = “Cool” ; mood = “Great” ; clothing = “Casual” ; }
Set the value of the variable ‘status’ to ‘Cool’, ‘mood’ to ‘Great’, and ‘clothing’ to ‘casual’ if the ‘day’ is equal to ‘Sunday’
17
Note: No semicolon after the closing curly brace
Compound Statements
if: Example 3
if ( (day == “Sunday”) || (day == “Saturday”) ) {
bhola = “Cool” ; mood = “Great” ; clothing = “Casual” ;
}