Chapter 3 PDF
Chapter 3 PDF
Chapter 3 PDF
Web Developers
1
Lecture
Presented By
Daw Khin Chit Bo
Chapter 3
2
Language Basics
Reviewing syntax
Working with data types
Working with flow-control statements
Understanding functions
Language Basics
3
Syntax
Case-sensitivity
Identifiers
Comments
Statements
Variables
Data Types
Operators
Functions
Identifiers
5
var y = 17;
var x = 4; Ans = x + y;
Ans => 15
var y = 11;
Ans = z + x;
var z = “cat”; Ans => cat4
var x = 4; Ans = x + y + z;
Ans => 15cat
var y = 11;
Ans = q + x + y;
var z = “cat”; Ans => 17411
var q = “17”;
Data Types
12
A statement is a Examples:
section of JavaScript Last_name = “Dunn”;
that can be evaluated x = 10 ;
by a Web browser
y = x*x ;
A script is simply a
collection of
statements
Operators
22
+ Addition == Equality
- Subtraction != Inequality
* Multiplication ! Logical NOT
/ Division && Logical AND
% Modulus || Logical OR
++ Increment ? Conditional
- - Decrement Selection
Arithmetic Operators and
Unary Operators
23
Assignment Operators
24
Comparison Operators
25
Logical Operators
26
String Operators and
Conditional27 Operators
The + operator, and the += operator can also be used to
concatenate (add) strings.
list: {
text += cars[0] + "<br>";
text += cars[1] + "<br>";
break list;
text += cars[2] + "<br>"; BMW
text += cars[3] + "<br>"; Volvo
}
The break and continue Statements
37
var text = ""; var text = "";
var i = 0; var i;
while (i < 5) for (i = 0; i < 5; i++)
{ {
text += "<br>The number is " + i; if (i === 3)
i++; { continue; }
if (i === 3) text += "The number is " + i +
{ "<br>";
break; }
} The number is 0
} The number is 1
The number is 0 The number is 2
The number is 1 The number is 4
The number is 2
The switch Statement
38
is a part of JavaScript's
"Conditional" Statements,
which are used to perform
different actions based on
different conditions.
is often used together with a
break or a default keyword
(or both).
break : breaks out of the
switch block.
default : specifies some
code to run if there is no case
match.
Functions
39
z = 3; Input/Argument: x
sqr_z = square(z);
Output: x*x
Example: Function
42
function sum_of_squares(num1,num2)
{return (num1*num1) + (num2*num2);}
function sum_of_squares(num1,num2)
{return (square(num1) + square(num2));}