JavaScript Day 1.pptx - 2
JavaScript Day 1.pptx - 2
Scripting Language
Programming Language
Scripting vs. Programming vs. Markup
Language
▪ Scripting Language
▪ Interpreted command by command and remain in their original form.
▪ Programming Language
▪ Compiled, converted permanently into binary executable files (i.e., zeros and
ones) before they are run.
▪ Markup Language
▪ A text-formatting language designed to transform raw text into structured
documents, by inserting procedural and descriptive markup into the raw text.
Late 1995
V1.3 V1.6
V1.5 V1.8.5
V1.0 ECMAScript 1 ECMAScript ECMAScript 6
ECMAScript 3 ECMAScript 5
&2 for XML
What we can do with
Web JavaScript
Application
Infinite
Scrolling
IOT Parallax
Games
After
Before
JavaScript Characteristics
▪ Case sensitive.
▪ Object-based.
▪ Event-Driven.
▪ Browser-Dependent.
▪ Interpreted language.
▪ Dynamic.
Where we can write
JavaScript Code
HTML File External File
Script Tag
• Head or Body
Filename.js + Script
tag
Event Handling
Data
Type
Variables
Name
Variable
Value
Address
Variables Names
First char a-z or A-Z or _
No whitespaces
Case-sensitive
Number
String
Boolean
Objects
NAME
var x = 5
VALUE
Variable
Declaration
Comments
// single line of text
/* multiline
of text */
Arithmetic Operators
Operator Description Example Result
+ Addition x=y+2 x=7
▪ typeof Operator
• A unary operator returns a string that
• represents the data type.
▪ The return values of using typeof can be one of the following:
• "number", "string", "Boolean", "undefined", "object", or "function".
▪ Example:
▪ var myName = “JavaScript”;
▪ typeof myName; //string
JavaScript Expression
An expression is a part of a statement that is evaluated as a value.
Main types of expressions:
▪ Left-hand-side “Assignment”
▪ a = 25; 🡺 assign RHS to variable of LHS
▪ Arithmetic
▪ 10 + 12; 🡺evaluates to sum of 10 and 12
▪ String
▪ “Hello” + ” All !!”; 🡺 evaluates to new string
▪ Logical
▪ 25<27 🡺 evaluates to the Boolean value
Control Statements
Conditional Statements
if
switch
Loop Statements
for
for in
while
do-while
Conditional Statements
If switch
do-while for in
Output
JavaScript Functions
A function is an organized block of reusable code (a set of statements)
that handles and performs actions generated by user events.
▪ Functions categorized into
• built-in functions improve your program's efficiency and readability.
• user defined functions , created by developer to make your programs
scalable.
▪ Function executes when it is called.
• from another function
• from a user event, called by an event or
• from a separate <script> block.
Global functions
Function Description
eval() Evaluates a string and executes it as if it was script
code
isFinite() Determines whether a value is a finite, legal number
isNaN() Determines whether a value is an illegal number
Number() Converts an object's value to a number
parseFloat() Parses a string and returns a floating-point number
parseInt() Parses a string and returns an integer
String() Converts an object's value to a string
Communicating with the User
▪ Four ways of communication:
▪one that displays a text message in a pop-up window