UNIT - 05
JAVASCRIPT
UNIT LIST
1. OVERVIEW OF JAVASCRIPT
2. GENERAL SYNTACTIC CHARACTERISTICS
3. PRIMITIVES
4. VARIABLES
5. OPERATIONS AND EXPRESSIONS
6. CONTROL STATEMENTS
7. ARRAYS
8. FUNCTIONS
9. POP-UP BOXES
WHAT IS JAVASCRIPT?
JavaScript is a high-level programming language
JavaScript was intvented by Brendan Eich in 1995
It is a Just-in-time complied
Evergreen programming language as used in both
frontend and backend
Event based Ex: click, load etc..
It is a Brain of the Web Page
U SE S OF JAVA SC R I PT
Both Frontend and Backend
Popularly used for online form submission
Web development uses Ex : Dropdown menu, Video Player, maps,
Pop-up window ect..
Real Time Networking Apps Ex: Video Streaming, chats etc..
AFTER LEARNING JAVASCRIPT WILL BECOME
Frontend Developer
Backend Developer
Full Stack Developer
SYNTATIC CHARACTERISTICS OF JAVASCRIPT
WE can Insert the SCRIPT element in a Web Page in 2 ways :
1) In the HEAD element
2) In the BODY element
1) JavaScript in the Head Element
<head>
<script type =“text/ javascript”> document.write(“HELLO WORLD”);
<script>
</head>
2) JavaScript in the Body Element
<body>
<script type =“text/ javascript”> document.write(“HELLO WORLD”);
<script>
</body>
FUNDAMENTAL CONCEPTS OF JAVASCRIPT
1) Premetives: The built-in data types of JavaScript are know as primitives or primitives
data types
Primitive datatypes in JavaScript are:
a) Number Ex: 23, 23.4
b) String Ex: “Computer”, ‘Hello’
c) Boolean Ex: True, False
d) Null
2) Variables: In Javascript, data can be temporarily stored in variables.
Syntax: var variable_name;
3) Operators: An operator performs an operation on operands is called as Operators
Operator
Ex:
a b
Operands
List of Operators :
1) Arithemetic Operator: +, -, *, /, %
2) Relational Operator: <, >, <=, >=, ==, !=
3) Assignment Operator: =, +=, -=, *=, /=, %=
4) Logical Operator: &&, ||, !
6) Bitwise Operator: &, |, ^,~, <<, >>
5) Ternary Operator: ?:
CONTROL STATEMENTS IN JAVASCRIPT
In JavaScript Control flow statements are divided into following
categories :
1)Selection Statemets
2)Loop
3)Jump Statements
4)Selection Statements : These statements are used to execute a
particular block of code if a ceratin condition is true
The Selection Statements are:
if, if-else, else-if ladder, switch case
a) If Statement
syntax:
if(condition)
{
statement;
b) If-else
syntax:
if(condition)
{
statement 1;
}
else
{
statement 2;
}
c) else- if ladder
syntax:
if(condition1)
statement 1;
else
if(condition2)
statement 2;
else
if(condition3)
statement 3;
else
statement n;
2) Loops : Repeatedly execute the block of statements until the becomes condition false
The Looping statements are:
while loop, do-while loop, for loop
a) while loop:
syntax:
while(condition)
{
statement;
}
b) do-while loop:
syntax:
do
{
Statement;
}
while(condition);
c) for loop:
synatax:
for(initialization; condition; Inc/Dec)
{
statements;
}
3) Jump Statements: Moving the control from one statement to another statement or one
function to another function
Jump statements in JavaScript are:
continue, break
a) continue:
syntax:
continue;
b) break:
syntax:
break;
ARRAYS
Array is a homogenous collection of data elemets of same datatype that are enclosed in
square brackets ([ ]).
Syntax:
var variable_name = [value1, value2, …….., valueN];
Ex:
var emp=[“anju”, “charu”, “manu”];
Some Built-In Functions for Arrays
concat()
fill()
index()
isarray()
pop()
push()
reverse()
sort()
toString()
FUNCTIONS
Function is a set of statements to perform a particular task.
There are two types of functions in JavaScript:
1) User-defined functions
2) Built-in functions
1) User-defined functions
A user-defined function is a function that a user creates for a program or
environment.
Syntax:
function function_name(parameter_name1, parameter_2,…….,
parameter_nameN)
{
// Block of Code
}
2) Built-in functions
JavaScript provides a number of built-in global functions to work with JavaScript
programs
Function Description
alert() Displays Information in a message box
prompt() Displays a message box OK or Cancle
confirm() Displays a message box with two buttons, OK an
Cancle
eval() Evaluates and executes a string and returns a result
IsFinite() Returns a boolean value, true or false
isNaN Determines whether or not a value is an illegal number.
NaN stands for Not a Number
parseInt() Extract a number from the beginning of a string,
returns integer value
parseFloat() Extract a number from the beginning of a string,
returns floating-point value
number() Converts value of an object into a number
escape() Encode a string
unescape() Decode a string
POP-UP BOXES
A popup boxes is a window that displays a message along with an OK button. The popup box
may also contain a Cancle button.
The popup boxes are:
1) The alert box
2) The confirm box
3) The prompt box
4) The alert box :
The alert box is generally used to display an alert message while executing the JavaScript
code.
2) The confirm box :
The confirm box is an advanced form of the alert box. It is used to display a message as well
as returns a true or false value.
3) The prompt box :
The prompt box is used to input a value from user. It contains a text box and OK and Cancle
buttons.