SlideShare a Scribd company logo
INTRODUCTION TO
JAVASCRIPT
By,
Divya K.S
WHAT IS JAVASCRIPT?
JavaScript is a lightweight, interpreted programming language with
object-oriented capabilities .
It allows you to build interactivity into otherwise static HTML pages.
JavaScript is a lightweight, interpreted programming language
Designed for creating network-centric applications
Complementary to and integrated with Java
Complementary to and integrated with HTML.
ADVANTAGES OF JAVASCRIPT:
The merits of using JavaScript are:
Less server interaction: The user input can be validated before sending
the page to the server. This puts fewer loads on the server.
Immediate feedback to the visitors: Users don't have to wait for a page
reload to see if they have forgotten to enter something.
Increased interactivity: Interfaces can be created that react when the
user hovers over them with a mouse or activates them via the
keyboard.
Richer interfaces: JavaScript can include such items as drag-and-drop
components and sliders to give a Rich Interface to your site visitors.
LIMITATIONS OF JAVASCRIPT:
Client-side JavaScript does not allow the reading or writing of
files. This has been kept for security reason.
JavaScript cannot be used for networking applications because
there is no such support available.
JavaScript doesn't have any multithreading or multiprocessing
capabilities.
DOCUMENT OBJECT MODEL
DOCUMENT OBJECT
When an HTML document is loaded into a web browser, it becomes
a document object.
The document object is the root node of the HTML document and the
"owner" of all other nodes:
(element nodes, text nodes, attribute nodes, and comment nodes).
The document object provides properties and methods to access all node
objects, from within JavaScript.
SCRIPTS
The script tag takes two important attributes:
language: This attribute specifies what scripting language is
used. Its value will be javascript.
type: This attribute is what is now recommended to indicate
the scripting language in use and its value should be set to
"text/javascript".
So the JavaScript segment will be:
<script language="javascript" type="text/javascript"> JavaScript
code</script>
JavaScript program to print "Hello BCA".
<html>
<body>
<script language="javascript" type="text/javascript">
document.write("Hello BCA!")
</script>
</body>
</html>
OPERATOR
Consider 4 + 5 =9. Here 4 and 5 are called operands and + is called
operator. JavaScript language supports following type of operators.
Arithmetic Operators
Comparision Operators
Logical (or Relational) Operators
Assignment Operators
Conditional (or ternary) Operators
ARITHMETIC OPERATORS:
Operator Description
+ Adds two operands
- Subtracts second operand from the first
* Multiply both operands
/ Divide numerator by denumerator
% Modulus Operator and remainder of after an integer division
++ Increment operator, increases integer value by one
-- Decrement operator, decreases integer value by one
COMPARISON OPERATORS:
Operato
r
Description
==
Checks if the values of two operands are equal or not, if yes then condition
becomes true.
!=
Checks if the values of two operands are equal or not, if values are not equal
then condition becomes true.
>
Checks if the value of left operand is greater than the value of right operand,
if yes then condition becomes true.
<
Checks if the value of left operand is less than the value of right operand, if
yes then condition becomes true.
>=
Checks if the value of left operand is greater than or equal to the value of
right operand, if yes then condition becomes true.
<=
Checks if the value of left operand is less than or equal to the value of right
LOGICAL OPERATORS:
Operator Description
&&
Called Logical AND operator. If both the operands are non zero
then then condition becomes true.
||
Called Logical OR Operator. If any of the two operands are non
zero then then condition becomes true.
!
Called Logical NOT Operator. Use to reverses the logical state of
its operand. If a condition is true then Logical NOT operator will
make false.
THE BITWISE OPERATORS:
Operator Description
&
Called Bitwise AND operator. It performs a Boolean AND operation on each bit of
its integer arguments.
|
Called Bitwise OR Operator. It performs a Boolean OR operation on each bit of its
integer arguments.
^
Called Bitwise XOR Operator. It performs a Boolean exclusive OR operation on
each bit of its integer arguments. Exclusive OR means that either operand one is
true or operand two is true, but not both.
~
Called Bitwise NOT Operator. It is a is a unary operator and operates by reversing
all bits in the operand.
ASSIGNMENT OPERATORS:
Operator Description
=
Simple assignment operator, Assigns values from right side operands to left side
operand
+=
Add AND assignment operator, It adds right operand to the left operand and assign the
result to left operand
- =
Subtract AND assignment operator, It subtracts right operand from the left operand
and assign the result to left operand
*=
Multiply AND assignment operator, It multiplies right operand with the left operand
and assign the result to left operand
/=
Divide AND assignment operator, It divides left operand with the right operand and
assign the result to left operand
%=
Modulus AND assignment operator, It takes modulus using two operands and assign
the result to left operand
MISCELLANEOUS OPERATOR
The Conditional Operator (? :)
The conditional operator first evaluates an expression for a true or false value and then
executes one of the two given statements depending upon the result of the evaluation. The
conditional operator has this syntax:
Operator Description Example
? : Conditional Expression
If Condition is true ? Then
value X : Otherwise value Y
CONDITIONAL STATEMENTS
JavaScript supports conditional statements which are used to perform
different actions based on different conditions. JavaScript supports
following forms of if..else statement:
if statement
if...else statement
if...else if... statement.
if statement:
The if statement is the fundamental control
statement that allows JavaScript to make decisions
and execute statements conditionally.
if (expression)
{
Statement(s) to be executed if
expression is true
}
EXAMPLE FOR IF STATEMENT
<script type="text/javascript">
var age = 20;
if( age > 18 )
{
document.write("<b>Qualifies for driving</b>");
}
</script>
IF...ELSE STATEMENT:
The if...else statement is the next form of control statement that allows JavaScript to execute statements in
more controlled way.
 Here JavaScript expression is evaluated. If the resulting value is true, given statement(s) in
the if block, are executed. If expression is false then given statement(s) in the else block, are
executed.
if (expression)
{
Statement(s) to be executed if expression is true}
Else
{
Statement(s) to be executed if expression is false
}
EXAMPLE FOR IF-ELSE STATEMENT
<script type="text/javascript">
var age = 15;
if( age > 18 )
{
document.write("<b>Qualifies for driving</b>");
}
Else
{
document.write("<b>Does not qualify for driving</b>");
}
</script>
IF...ELSE IF... STATEMENT:
The if...else if... statement is the one level advance form of control statement that allows JavaScript to
make correct decision out of several conditions
if (expression 1)
{
Statement(s) to be executed if expression 1 is true
}
else if (expression 2)
{
Statement(s) to be executed if expression 2 is true
}
else if (expression 3)
{
Statement(s) to be executed if expression 3 is true
}
Else
{
EXAMPLE FOR IF-ELSE-IF STATEMENT
<script type="text/javascript">
var book = "maths";
if( book == "history" )
{
document.write("<b>History Book</b>");
}
else if( book == "maths" )
{
document.write("<b>Maths Book</b>");
}
else if( book == "economics" )
{
document.write("<b>Economics Book</b>");
}
Else
{
document.write("<b>Unknown Book</b>");
}
SWITCH STATEMENT
The basic syntax of the switch statement is to give an expression to evaluate and several
different statements to execute based on the value of the expression. The interpreter
checks each case against the value of the expression until a match is found. If
nothing matches, a default condition will be used.
switch (expression)
{
case condition 1: statement(s)
break;
case condition 2: statement(s)
break;
...
case condition n: statement(s)
break;
default: statement(s)
}
EXAMPLE FOR SWITCH CASE STATEMENT
<script type="text/javascript">
var grade='A';
document.write("Entering switch block<br />");
switch (grade)
{ case 'A': document.write("Good job<br />");
break;
case 'B': document.write("Pretty good<br />");
break;
case 'C': document.write("Passed<br />");
break;
case 'D': document.write("Not so good<br />");
break;
case 'F': document.write("Failed<br />");
break;
default: document.write("Unknown grade<br />");
}
document.write("Exiting switch block");
</script>
PRECACHING IMAGES WITH JAVASCRIPT
JavaScript helps you to load images into the browser’s memory cache without displaying
them.This images is the precaching images. And this technique preload the images into the
browser cache when the page initially loads.
Steps:
In order to precache an image we need to construct an image object in memory. Image object
created in memory is dissimilar from the document image object aka <IMG>tag.
HERE YOU GO:
Parameters to the constructor are the pixel width and height of the image
So the image object exists in memory. Now you can assign a filename or URL to the src
property of that image object:
1var myImage = new Image(width, height)
1myImage.src = “someImage.jpeg”
IMAGE ROLLOVERS
Image rollovers (sometimes also called Image Mouse Overs or mouse-overs) can be
found in numerous websites on the Internet today. You've probably seen them
around too: when you move your mouse cursor over a button on a particular
site, the button appears to be depressed. Move your mouse cursor away, and the
button pops out again.
Image rollovers are implemented by creating two images for the same button. The
first image is that which you want displayed when the mouse is not hovering
over it, typically the "undepressed" or "up" state of a button.
The second image is the graphic you want displayed when the mouse pointer is over
the graphic, usually showing the button in a depressed or "down" state.
FORM AND FORM ELEMENT
The use of HTML forms is basic to almost all JavaScript programs. This chapter explains
the details of programming with forms in JavaScript. It is assumed that you are
already somewhat familiar with the creation of HTML forms and with the input
elements that they contain.
FORM VALIDATION
Form validation normally used to occur at the server, after the client had entered
all the necessary data and then pressed the Submit button. If the data entered
by a client was incorrect or was simply missing, the server would have to send
all the data back to the client and request that the form be resubmitted with
correct information.
TYPES OF FORM VALIDATION
Form validation generally performs two functions.
Basic Validation − First of all, the form must be checked to
make sure all the mandatory fields are filled in. It would require just a loop
through each field in the form and check for data.
Data Format Validation − Secondly, the data that is entered
must be checked for correct form and value. Your code must include
appropriate logic to test correctness of data.
Introduction to java script
Introduction to java script
Introduction to java script
Introduction to java script
JAVASCRIPT OBJECTS
• Numbers can be objects (if defined with the new keyword)
• Strings can be objects (if defined with the new keyword)
• Dates are always objects
• Regular expressions are always objects
• Arrays are always objects
• Functions are always objects
JavaScript Primitives
A primitive value is a value that has no properties or methods.
A primitive data type is data that has a primitive value.
JavaScript defines 5 types of primitive data types:
• string
• number
• boolean
• null
• undefined
JAVASCRIPT BUILT-IN OBJECTS
1. Math object
These objects are used for simple data processing in the JavaScript
Math Property Description
SQRT2 Returns square root of 2.
PI Returns Π value.
E  Returns Euler's Constant.
LN2 Returns natural logarithm of 2.
LN10 Returns natural logarithm of 10.
LOG2E Returns base 2 logarithm of E.
LOG10E Returns 10 logarithm of E.
MATH METHODS
Methods Description
abs() Returns the absolute value of a number.
acos() Returns the arccosine (in radians) of a number.
ceil() Returns the smallest integer greater than or equal to a number.
cos() Returns cosine of a number.
floor() Returns the largest integer less than or equal to a number.
log() Returns the natural logarithm (base E) of a number.
max() Returns the largest of zero or more numbers.
min() Returns the smallest of zero or more numbers.
pow() Returns base to the exponent power, that is base exponent.
2. DATE OBJECT
• Date is a data type.
• Date object manipulates date and time.
• Date() constructor takes no arguments.
• Date object allows you to get and set the year, month, day, hour, minute,
second and millisecond fields.
Syntax:
var variable_name = new Date();
Example:
var current_date = new Date();
Methods Description
Date() Returns current date and time.
getDate() Returns the day of the month.
getDay() Returns the day of the week.
getFullYear() Returns the year.
getHours() Returns the hour.
getMinutes() Returns the minutes.
getSeconds() Returns the seconds.
getMilliseconds() Returns the milliseconds.
getTime() Returns the number of milliseconds since January 1, 1970 at 12:00 AM.
getTimezoneOffset() Returns the timezone offset in minutes for the current locale.
getMonth() Returns the month.
setDate() Sets the day of the month.
setFullYear() Sets the full year.
setHours() Sets the hours.
setMinutes() Sets the minutes.
setSeconds() Sets the seconds.
setMilliseconds() Sets the milliseconds.
setTime() Sets the number of milliseconds since January 1, 1970 at 12:00 AM.
setMonth() Sets the month.
toDateString() Returns the date portion of the Date as a human-readable string.
toLocaleString() Returns the Date object as a string.
toGMTString() Returns the Date object as a string in GMT timezone.
valueOf() Returns the primitive value of a Date object.
3. String Object
• String objects are used to work with text.
• It works with a series of characters.
Syntax:
var variable_name = new String(string);
Example:
var s = new String(string);
STRING PROPERTIES
Properties Description
length It returns the length of the string.
prototype It allows you to add properties and
methods to an object.
constructor It returns the reference to the String
function that created the object.
Window Object
The window object represents an open window in a browser.
If a document contain frames (<iframe> tags), the browser creates one window
object for the HTML document, and one additional window object for each
frame.
Property Description
closed Returns a Boolean value indicating whether a window has been closed or not
console Returns a reference to the Console object, which provides methods for logging
information to the browser's console (See Console object)
defaultStatus Sets or returns the default text in the statusbar of a window
document Returns the Document object for the window (See Document object)
frameElement Returns the <iframe> element in which the current window is inserted
frames Returns all <iframe> elements in the current window
A Document object
A Document object represents the HTML document that is displayed in that window. The Document object has
various properties that refer to other objects which allow access to and modification of document content.
The way a document content is accessed and modified is called the Document Object Model, or DOM. The
Objects are organized in a hierarchy. This hierarchical structure applies to the organization of objects in a
Web document.
• Window object − Top of the hierarchy. It is the outmost element of the object hierarchy.
• Document object − Each HTML document that gets loaded into a window becomes a document object. The
document contains the contents of the page.
• Form object − Everything enclosed in the <form>...</form> tags sets the form object.
• Form control elements − The form object contains all the elements defined for that object such as text fields,
buttons, radio buttons, and checkboxes.
THANK YOU

More Related Content

DOC
Introduction to java script
nanjil1984
 
RTF
Java scripts
Capgemini India
 
DOC
Basics java scripts
ch samaram
 
PPTX
1. java script language fundamentals
Rajiv Gupta
 
PPTX
Java script
Rajkiran Mummadi
 
PPTX
Java script
Sadeek Mohammed
 
PPT
Java script final presentation
Adhoura Academy
 
PPT
Java script
Soham Sengupta
 
Introduction to java script
nanjil1984
 
Java scripts
Capgemini India
 
Basics java scripts
ch samaram
 
1. java script language fundamentals
Rajiv Gupta
 
Java script
Rajkiran Mummadi
 
Java script
Sadeek Mohammed
 
Java script final presentation
Adhoura Academy
 
Java script
Soham Sengupta
 

What's hot (20)

PPTX
Java Script An Introduction By HWA
Emma Wood
 
PPTX
Java script
Shyam Khant
 
PPTX
Java script Session No 1
Saif Ullah Dar
 
PPTX
Java script
Jay Patel
 
PPT
Java script -23jan2015
Sasidhar Kothuru
 
PDF
Basic JavaScript Tutorial
DHTMLExtreme
 
PPTX
Javascript
Nagarajan
 
PDF
Javascript
Aditya Gaur
 
PPT
Java Script ppt
Priya Goyal
 
DOCX
Java script basics
Thakur Amit Tomer
 
PPTX
Basics of Javascript
poojanov04
 
PPT
Java script
ITz_1
 
PDF
8 introduction to_java_script
Vijay Kalyan
 
PDF
Javascript - Tutorial
adelaticleanu
 
PPTX
Introduction to JavaScript Programming
Collaboration Technologies
 
PPTX
Java script basics
Shrivardhan Limbkar
 
PPTX
Javascript functions
Alaref Abushaala
 
PPTX
Introduction to Javascript
ambuj pathak
 
PPTX
Introduction To JavaScript
Reema
 
PPTX
An Introduction to JavaScript
tonyh1
 
Java Script An Introduction By HWA
Emma Wood
 
Java script
Shyam Khant
 
Java script Session No 1
Saif Ullah Dar
 
Java script
Jay Patel
 
Java script -23jan2015
Sasidhar Kothuru
 
Basic JavaScript Tutorial
DHTMLExtreme
 
Javascript
Nagarajan
 
Javascript
Aditya Gaur
 
Java Script ppt
Priya Goyal
 
Java script basics
Thakur Amit Tomer
 
Basics of Javascript
poojanov04
 
Java script
ITz_1
 
8 introduction to_java_script
Vijay Kalyan
 
Javascript - Tutorial
adelaticleanu
 
Introduction to JavaScript Programming
Collaboration Technologies
 
Java script basics
Shrivardhan Limbkar
 
Javascript functions
Alaref Abushaala
 
Introduction to Javascript
ambuj pathak
 
Introduction To JavaScript
Reema
 
An Introduction to JavaScript
tonyh1
 
Ad

Similar to Introduction to java script (20)

PPTX
Java script.pptx v
22x026
 
DOCX
Unit 2.5
Abhishek Kesharwani
 
PPTX
Unit - 4 all script are here Javascript.pptx
kushwahanitesh592
 
PPTX
JAVASCRIPT - LinkedIn
Gino Louie Peña, ITIL®,MOS®
 
PDF
Unit 2.5
Abhishek Kesharwani
 
PPTX
FFW Gabrovo PMG - JavaScript 1
Toni Kolev
 
PPTX
Java script session 4
Saif Ullah Dar
 
PDF
Javascript basics
shreesenthil
 
PPTX
javascriptbasicsPresentationsforDevelopers
Ganesh Bhosale
 
PPSX
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
PPTX
Learning JavaScript Programming
Hriday Ahmed
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
JavaScript Operators
Dr. Jasmine Beulah Gnanadurai
 
PDF
Ch3- Java Script.pdf
HASENSEID
 
PPT
Introduction to javascript.ppt
BArulmozhi
 
PPTX
Javascript
Gita Kriz
 
PDF
Javascript tutorial basic for starter
Marcello Harford
 
PPTX
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
PPT
data-types-operators-datatypes-operators.ppt
Gagan Rana
 
PPT
UNIT 3.ppt
MadhurRajVerma1
 
Java script.pptx v
22x026
 
Unit - 4 all script are here Javascript.pptx
kushwahanitesh592
 
JAVASCRIPT - LinkedIn
Gino Louie Peña, ITIL®,MOS®
 
FFW Gabrovo PMG - JavaScript 1
Toni Kolev
 
Java script session 4
Saif Ullah Dar
 
Javascript basics
shreesenthil
 
javascriptbasicsPresentationsforDevelopers
Ganesh Bhosale
 
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
Learning JavaScript Programming
Hriday Ahmed
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
JavaScript Operators
Dr. Jasmine Beulah Gnanadurai
 
Ch3- Java Script.pdf
HASENSEID
 
Introduction to javascript.ppt
BArulmozhi
 
Javascript
Gita Kriz
 
Javascript tutorial basic for starter
Marcello Harford
 
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
data-types-operators-datatypes-operators.ppt
Gagan Rana
 
UNIT 3.ppt
MadhurRajVerma1
 
Ad

More from DivyaKS12 (16)

PPTX
Web programming using PHP and Introduction with sample codes
DivyaKS12
 
PPTX
Naïve Bayes Classification (Data Mining)
DivyaKS12
 
PPTX
K- Nearest Neighbour Algorithm.pptx
DivyaKS12
 
PPTX
NUMBER SYSTEM.pptx
DivyaKS12
 
PPTX
unit 3.pptx
DivyaKS12
 
PPTX
PCCF UNIT 2.pptx
DivyaKS12
 
PPTX
PCCF UNIT 1.pptx
DivyaKS12
 
PPTX
DBMS-INTRODUCTION.pptx
DivyaKS12
 
PPTX
Database models and DBMS languages
DivyaKS12
 
PDF
Operation research (definition, phases)
DivyaKS12
 
PPTX
Types of Computer Modem
DivyaKS12
 
PDF
UI controls in Android
DivyaKS12
 
PDF
Fragments In Android
DivyaKS12
 
PDF
Android os(comparison all other mobile os)
DivyaKS12
 
PPTX
CSS
DivyaKS12
 
PPTX
Internet technology
DivyaKS12
 
Web programming using PHP and Introduction with sample codes
DivyaKS12
 
Naïve Bayes Classification (Data Mining)
DivyaKS12
 
K- Nearest Neighbour Algorithm.pptx
DivyaKS12
 
NUMBER SYSTEM.pptx
DivyaKS12
 
unit 3.pptx
DivyaKS12
 
PCCF UNIT 2.pptx
DivyaKS12
 
PCCF UNIT 1.pptx
DivyaKS12
 
DBMS-INTRODUCTION.pptx
DivyaKS12
 
Database models and DBMS languages
DivyaKS12
 
Operation research (definition, phases)
DivyaKS12
 
Types of Computer Modem
DivyaKS12
 
UI controls in Android
DivyaKS12
 
Fragments In Android
DivyaKS12
 
Android os(comparison all other mobile os)
DivyaKS12
 
Internet technology
DivyaKS12
 

Recently uploaded (20)

PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
PPTX
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
Introduction and Scope of Bichemistry.pptx
shantiyogi
 

Introduction to java script

  • 2. WHAT IS JAVASCRIPT? JavaScript is a lightweight, interpreted programming language with object-oriented capabilities . It allows you to build interactivity into otherwise static HTML pages. JavaScript is a lightweight, interpreted programming language Designed for creating network-centric applications Complementary to and integrated with Java Complementary to and integrated with HTML.
  • 3. ADVANTAGES OF JAVASCRIPT: The merits of using JavaScript are: Less server interaction: The user input can be validated before sending the page to the server. This puts fewer loads on the server. Immediate feedback to the visitors: Users don't have to wait for a page reload to see if they have forgotten to enter something. Increased interactivity: Interfaces can be created that react when the user hovers over them with a mouse or activates them via the keyboard. Richer interfaces: JavaScript can include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.
  • 4. LIMITATIONS OF JAVASCRIPT: Client-side JavaScript does not allow the reading or writing of files. This has been kept for security reason. JavaScript cannot be used for networking applications because there is no such support available. JavaScript doesn't have any multithreading or multiprocessing capabilities.
  • 6. DOCUMENT OBJECT When an HTML document is loaded into a web browser, it becomes a document object. The document object is the root node of the HTML document and the "owner" of all other nodes: (element nodes, text nodes, attribute nodes, and comment nodes). The document object provides properties and methods to access all node objects, from within JavaScript.
  • 7. SCRIPTS The script tag takes two important attributes: language: This attribute specifies what scripting language is used. Its value will be javascript. type: This attribute is what is now recommended to indicate the scripting language in use and its value should be set to "text/javascript". So the JavaScript segment will be:
  • 8. <script language="javascript" type="text/javascript"> JavaScript code</script> JavaScript program to print "Hello BCA". <html> <body> <script language="javascript" type="text/javascript"> document.write("Hello BCA!") </script> </body> </html>
  • 9. OPERATOR Consider 4 + 5 =9. Here 4 and 5 are called operands and + is called operator. JavaScript language supports following type of operators. Arithmetic Operators Comparision Operators Logical (or Relational) Operators Assignment Operators Conditional (or ternary) Operators
  • 10. ARITHMETIC OPERATORS: Operator Description + Adds two operands - Subtracts second operand from the first * Multiply both operands / Divide numerator by denumerator % Modulus Operator and remainder of after an integer division ++ Increment operator, increases integer value by one -- Decrement operator, decreases integer value by one
  • 11. COMPARISON OPERATORS: Operato r Description == Checks if the values of two operands are equal or not, if yes then condition becomes true. != Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. <= Checks if the value of left operand is less than or equal to the value of right
  • 12. LOGICAL OPERATORS: Operator Description && Called Logical AND operator. If both the operands are non zero then then condition becomes true. || Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
  • 13. THE BITWISE OPERATORS: Operator Description & Called Bitwise AND operator. It performs a Boolean AND operation on each bit of its integer arguments. | Called Bitwise OR Operator. It performs a Boolean OR operation on each bit of its integer arguments. ^ Called Bitwise XOR Operator. It performs a Boolean exclusive OR operation on each bit of its integer arguments. Exclusive OR means that either operand one is true or operand two is true, but not both. ~ Called Bitwise NOT Operator. It is a is a unary operator and operates by reversing all bits in the operand.
  • 14. ASSIGNMENT OPERATORS: Operator Description = Simple assignment operator, Assigns values from right side operands to left side operand += Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand - = Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand *= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand /= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand %= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand
  • 15. MISCELLANEOUS OPERATOR The Conditional Operator (? :) The conditional operator first evaluates an expression for a true or false value and then executes one of the two given statements depending upon the result of the evaluation. The conditional operator has this syntax: Operator Description Example ? : Conditional Expression If Condition is true ? Then value X : Otherwise value Y
  • 16. CONDITIONAL STATEMENTS JavaScript supports conditional statements which are used to perform different actions based on different conditions. JavaScript supports following forms of if..else statement: if statement if...else statement if...else if... statement.
  • 17. if statement: The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. if (expression) { Statement(s) to be executed if expression is true }
  • 18. EXAMPLE FOR IF STATEMENT <script type="text/javascript"> var age = 20; if( age > 18 ) { document.write("<b>Qualifies for driving</b>"); } </script>
  • 19. IF...ELSE STATEMENT: The if...else statement is the next form of control statement that allows JavaScript to execute statements in more controlled way.  Here JavaScript expression is evaluated. If the resulting value is true, given statement(s) in the if block, are executed. If expression is false then given statement(s) in the else block, are executed. if (expression) { Statement(s) to be executed if expression is true} Else { Statement(s) to be executed if expression is false }
  • 20. EXAMPLE FOR IF-ELSE STATEMENT <script type="text/javascript"> var age = 15; if( age > 18 ) { document.write("<b>Qualifies for driving</b>"); } Else { document.write("<b>Does not qualify for driving</b>"); } </script>
  • 21. IF...ELSE IF... STATEMENT: The if...else if... statement is the one level advance form of control statement that allows JavaScript to make correct decision out of several conditions if (expression 1) { Statement(s) to be executed if expression 1 is true } else if (expression 2) { Statement(s) to be executed if expression 2 is true } else if (expression 3) { Statement(s) to be executed if expression 3 is true } Else {
  • 22. EXAMPLE FOR IF-ELSE-IF STATEMENT <script type="text/javascript"> var book = "maths"; if( book == "history" ) { document.write("<b>History Book</b>"); } else if( book == "maths" ) { document.write("<b>Maths Book</b>"); } else if( book == "economics" ) { document.write("<b>Economics Book</b>"); } Else { document.write("<b>Unknown Book</b>"); }
  • 23. SWITCH STATEMENT The basic syntax of the switch statement is to give an expression to evaluate and several different statements to execute based on the value of the expression. The interpreter checks each case against the value of the expression until a match is found. If nothing matches, a default condition will be used. switch (expression) { case condition 1: statement(s) break; case condition 2: statement(s) break; ... case condition n: statement(s) break; default: statement(s) }
  • 24. EXAMPLE FOR SWITCH CASE STATEMENT <script type="text/javascript"> var grade='A'; document.write("Entering switch block<br />"); switch (grade) { case 'A': document.write("Good job<br />"); break; case 'B': document.write("Pretty good<br />"); break; case 'C': document.write("Passed<br />"); break; case 'D': document.write("Not so good<br />"); break; case 'F': document.write("Failed<br />"); break; default: document.write("Unknown grade<br />"); } document.write("Exiting switch block"); </script>
  • 25. PRECACHING IMAGES WITH JAVASCRIPT JavaScript helps you to load images into the browser’s memory cache without displaying them.This images is the precaching images. And this technique preload the images into the browser cache when the page initially loads. Steps: In order to precache an image we need to construct an image object in memory. Image object created in memory is dissimilar from the document image object aka <IMG>tag. HERE YOU GO: Parameters to the constructor are the pixel width and height of the image So the image object exists in memory. Now you can assign a filename or URL to the src property of that image object: 1var myImage = new Image(width, height) 1myImage.src = “someImage.jpeg”
  • 26. IMAGE ROLLOVERS Image rollovers (sometimes also called Image Mouse Overs or mouse-overs) can be found in numerous websites on the Internet today. You've probably seen them around too: when you move your mouse cursor over a button on a particular site, the button appears to be depressed. Move your mouse cursor away, and the button pops out again. Image rollovers are implemented by creating two images for the same button. The first image is that which you want displayed when the mouse is not hovering over it, typically the "undepressed" or "up" state of a button. The second image is the graphic you want displayed when the mouse pointer is over the graphic, usually showing the button in a depressed or "down" state.
  • 27. FORM AND FORM ELEMENT The use of HTML forms is basic to almost all JavaScript programs. This chapter explains the details of programming with forms in JavaScript. It is assumed that you are already somewhat familiar with the creation of HTML forms and with the input elements that they contain.
  • 28. FORM VALIDATION Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button. If the data entered by a client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with correct information.
  • 29. TYPES OF FORM VALIDATION Form validation generally performs two functions. Basic Validation − First of all, the form must be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data. Data Format Validation − Secondly, the data that is entered must be checked for correct form and value. Your code must include appropriate logic to test correctness of data.
  • 34. JAVASCRIPT OBJECTS • Numbers can be objects (if defined with the new keyword) • Strings can be objects (if defined with the new keyword) • Dates are always objects • Regular expressions are always objects • Arrays are always objects • Functions are always objects
  • 35. JavaScript Primitives A primitive value is a value that has no properties or methods. A primitive data type is data that has a primitive value. JavaScript defines 5 types of primitive data types: • string • number • boolean • null • undefined
  • 36. JAVASCRIPT BUILT-IN OBJECTS 1. Math object These objects are used for simple data processing in the JavaScript Math Property Description SQRT2 Returns square root of 2. PI Returns Π value. E Returns Euler's Constant. LN2 Returns natural logarithm of 2. LN10 Returns natural logarithm of 10. LOG2E Returns base 2 logarithm of E. LOG10E Returns 10 logarithm of E.
  • 37. MATH METHODS Methods Description abs() Returns the absolute value of a number. acos() Returns the arccosine (in radians) of a number. ceil() Returns the smallest integer greater than or equal to a number. cos() Returns cosine of a number. floor() Returns the largest integer less than or equal to a number. log() Returns the natural logarithm (base E) of a number. max() Returns the largest of zero or more numbers. min() Returns the smallest of zero or more numbers. pow() Returns base to the exponent power, that is base exponent.
  • 38. 2. DATE OBJECT • Date is a data type. • Date object manipulates date and time. • Date() constructor takes no arguments. • Date object allows you to get and set the year, month, day, hour, minute, second and millisecond fields. Syntax: var variable_name = new Date(); Example: var current_date = new Date();
  • 39. Methods Description Date() Returns current date and time. getDate() Returns the day of the month. getDay() Returns the day of the week. getFullYear() Returns the year. getHours() Returns the hour. getMinutes() Returns the minutes. getSeconds() Returns the seconds. getMilliseconds() Returns the milliseconds. getTime() Returns the number of milliseconds since January 1, 1970 at 12:00 AM. getTimezoneOffset() Returns the timezone offset in minutes for the current locale. getMonth() Returns the month. setDate() Sets the day of the month. setFullYear() Sets the full year. setHours() Sets the hours. setMinutes() Sets the minutes. setSeconds() Sets the seconds. setMilliseconds() Sets the milliseconds. setTime() Sets the number of milliseconds since January 1, 1970 at 12:00 AM. setMonth() Sets the month. toDateString() Returns the date portion of the Date as a human-readable string. toLocaleString() Returns the Date object as a string. toGMTString() Returns the Date object as a string in GMT timezone. valueOf() Returns the primitive value of a Date object.
  • 40. 3. String Object • String objects are used to work with text. • It works with a series of characters. Syntax: var variable_name = new String(string); Example: var s = new String(string);
  • 41. STRING PROPERTIES Properties Description length It returns the length of the string. prototype It allows you to add properties and methods to an object. constructor It returns the reference to the String function that created the object.
  • 42. Window Object The window object represents an open window in a browser. If a document contain frames (<iframe> tags), the browser creates one window object for the HTML document, and one additional window object for each frame. Property Description closed Returns a Boolean value indicating whether a window has been closed or not console Returns a reference to the Console object, which provides methods for logging information to the browser's console (See Console object) defaultStatus Sets or returns the default text in the statusbar of a window document Returns the Document object for the window (See Document object) frameElement Returns the <iframe> element in which the current window is inserted frames Returns all <iframe> elements in the current window
  • 43. A Document object A Document object represents the HTML document that is displayed in that window. The Document object has various properties that refer to other objects which allow access to and modification of document content. The way a document content is accessed and modified is called the Document Object Model, or DOM. The Objects are organized in a hierarchy. This hierarchical structure applies to the organization of objects in a Web document. • Window object − Top of the hierarchy. It is the outmost element of the object hierarchy. • Document object − Each HTML document that gets loaded into a window becomes a document object. The document contains the contents of the page. • Form object − Everything enclosed in the <form>...</form> tags sets the form object. • Form control elements − The form object contains all the elements defined for that object such as text fields, buttons, radio buttons, and checkboxes.