Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

JAVASCRIPT

NANDITA T DAS
Topics to be Covered
Introduction
JS Comment
Variable
Data Type
Operator
Control Statement
Function
Object
Array
String
BOM & DOM
Validation
Events
Introduction
JavaScript is an Object-based scripting language.
JavaScript is not compiled but translated.

Scripting language:
A script or scripting language is a computer language with a series of commands
within a file that is capable of being executed without being compiled
How to write JS
<html>
<head>
<script type="text/javascript">
document.write(Welcome to JavaScript);
</script>
</head>
<body></body>
</html>
Where to write JS Code

JavaScript provides 3 places to put the JavaScript code


1. Within Head tag
2. Within Body tag
3. In .js file (external javaScript)
JS Comment
There are two types of comments in JavaScript.
Single-line Comment (//)
Multi-line Comment (/* your code here */ )
Variable
A JavaScript variable is simply a name of storage location

There are two types of variables in javascript


1. Local Variable
2. Global Variable
Data Types
There are two types of Data Types in JavaScript
1. Primitive
2. Non-Primitive
Operator
JavaScript operators are symbols that are used to perform operations on operands.
- Arithmetic Operator
- Comparison Operator
- Bitwise Operator
- Logical Operator
- Assignment Operator
- JS Special Operator
Control Statement
if
if else
If else if
Switch
Loop

There are four types of loops in JavaScript.


for loop
while loop
do-while loop
Function
functions are used to perform operations.

function functionName(){ //without argument


//logic
}

function functionName([arg1,arg2,,argN]){ //with argument


//logic
}
Object
A JavaScript object is an entity having state and behavior (properties and method). For example:
car, pen, bike, chair, glass, keyboard, monitor etc.
JavaScript is an object-based language. Everything is an object in JavaScript.
Here, we don't create class to get the object. But, we direct create objects.
Array
Array is an object that represents a collection of similar type of elements.
1. var arrayname=[value1,value2.....valueN];
var emp=["Sonoo","Vimal","Ratan"];
2. var emp = new array();
emp[0]=Sonoo;
emp[1]=Vimal;
emp[2]=Ratan;

3. var emp= new array("Sonoo","Vimal","Ratan");


String
The JavaScript string is an object that represents a sequence of characters.
There are 2 ways to create string in JavaScript
By string literal
By string object (using new keyword)
JavaScript String Methods
Let's see the list of JavaScript string methods with examples.
charAt(index)
concat(str)
indexOf(str)
lastIndexOf(str)
toLowerCase()
toUpperCase()
slice(beginIndex, endIndex)
trim()
BOM(Browser Object Model)
The Browser Object Model (BOM) is used to interact with the browser.
The default object of browser is window
DOM(Document Object Model)
The document object represents the whole html document.
When html document is loaded in the browser, it becomes a document object.
It is the root element that represents the html document.
Validation
It is important to validate the form submitted by the user because it can have inappropriate
values. So validation is must.
The JavaScript provides you the facility the validate the form
Through JavaScript, we can validate name, password, email, date, mobile number etc fields.
JS Events
Onclick
Ondblclick
Onsubmit
Onmouseover
Etc
Summary
JavaScript is an object-based scripting language.
It is lightweight and cross-platform.
JavaScript is used to create interactive websites

You might also like