You are on page 1of 13

1

JavaScript
Introduction

Compile by: Information Technology (IT)


2

Web based Scripting Language


Client Side Scripting Server Side Scripting

• PHP
• .NET
• Python

• VB Script • HTML
• JavaScript

Compile by: Information Technology (IT)


3

Why we learn JavaScript?


• JavaScript is an Event Based Programming
Language.

• Click • Key Press

• Double Click • Key Up

• Right Click • Load

• Mouse Hover • Unload

• Mouse Out • Resize


Compile by:
• Drag & Drop • Scroll Information Technology (IT)
4

JavaScript Data Types.


Names of Data Type in JavaScript
1. var var a = “Text here”; String

var a = 1000; Number


2. let
var a = True, False; Boolean
3. const var a = [“HTML”, “JS”]; Array

var a; Undefined

var a = {name: “JavaScript”;} Object

var a = null; Null


OBJECT Compile by:
Information Technology (IT)
5

Difference between JavaScript Variables.

VAR LET CONST


• Declared • Declared • Once declared

• Overwrite with • Overwrite with • Neither overwrite

same variable same variable with same

• Can be declared • Cannot be variable nor

again declared again declared again

Compile by:
Information Technology (IT)
6

Arithmetic Operators
Arithmetic operators can be used only with Number
Operator Name

+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation
% Modulus (Remainder)
++ Increment
-- Decrement

Compile by:
HTML & JavaScript Information Technology (IT)
7

Arithmetic Operators (Modulus %)

Usage of Modulus in JavaScript

7 Answer

2 14
- 14
0 Modulus (%)

Compile by:
HTML & JavaScript Information Technology (IT)
8

Different type of Comparison Operators:

Operator Description

== Equal
=== Equal value and equal type
!= Not equal
!== Not equal value and type
> Greater than
< Less than
>= Greater than equal to
<= Less than equal to

Compile by:
HTML & JavaScript Information Technology (IT)
9

If statement in JavaScript
var a = 20;
if (a > 30) {document.write(“Your message...”);}

Logical Operators in JavaScript


Comparison Operator Name Description
&& Logical AND Both statements must be true.

|| Logical OR Either one statement must be true.

! Logical NOT
var x= 20;
if (x >= 15 && x <= 25) {document.write(“Your message...”);}
var y= 20;
if (y >= 20 || y <= 19) {document.write(“Your message...”);}

Compile by:
Information Technology (IT)
10

If Else If statement in JavaScript

80 to 90 = in Merit
70 to 79 = A
60 to 69 = B
50 to 59 = C
40 to 49 = D
< 33 = FAIL
Compile by:
Information Technology (IT)
11

Ternary Operator in JavaScript

var x = 15;
var y;

(x >= 20) ? y = “True” : y = “False”;

Compile by:
Information Technology (IT)
12

What is a Computer Program?

A computer program is List of “instructions” to


be “executed” by a computer.

Compile by:
Information Technology (IT)
13

External JavaScriptAdvantages

var x = 15;
var y;

(x >= 20) ? y = “True” : y = “False”;

Compile by:
Information Technology (IT)

You might also like