Introduction To Javascript
Introduction To Javascript
JAVASCRIPT
JAVASCRIPT
JavaScript is used in millions of Web pages to
improve the design, validate forms, detect
browsers, create cookies, and much more.
JavaScript is the most popular scripting
language on the internet, and works in all
major browsers, such as Internet Explorer,
Mozilla, Firefox, Netscape, Opera.
WHAT IS JAVASCRIPT?
JavaScript was designed to add interactivity to HTML
pages
JavaScript is a scripting language (a scripting language is
a lightweight programming language)
A JavaScript consists of lines of executable computer
code
A JavaScript is usually embedded directly into HTML
pages
JavaScript is an interpreted language (means that scripts
execute without preliminary compilation)
Everyone can use JavaScript without purchasing a license
JavaScript Variables
Variables are used to store data.
A variable is a "container" for information you want
to store. A variable's value can change during the
script. You can refer to a variable by name to see its
value or to change its value.
Rules for variable names:
Variable names are case sensitive
They must begin with a letter or the underscore character
strname STRNAME (not same)
JavaScript Operators
Arithmetic Operators
Operator
+
Description
Example
Addition
x=2
Result
4
y=2
x+y
-
Subtraction
x=5
y=2
x-y
*
Multiplication
x=5
20
y=4
x*y
/
Division
15/5
5/2
%
++
Modulus (division
remainder)
Increment
2,5
5%2
10%8
10%2
x=5
x=6
x++
--
Decrement
x=5
x--
x=4
JavaScript Operators 2
Assignment Operators
Operator
Example
Is The Same As
x=y
x=y
+=
x+=y
x=x+y
-=
x-=y
x=x-y
*=
x*=y
x=x*y
/=
x/=y
x=x/y
%=
x%=y
x=x%y
JavaScript Operators - 3
Comparison Operators
Operator
Description
Example
==
is equal to
===
x=5
y="5"
is not equal
>
is greater than
<
is less than
>=
<=
JavaScript Operators - 4
Logical Operators
Operator
Description
Example
&&
and
x=6
y=3
or
x=6
y=3
(x==5 || y==5)
returns false
!
not
x=6
y=3
!(x==y) returns
true
Example
<script>
x=Hello World!
document.write(x)
</script>
<script>
alert("Hello World!")
</script>
Start of the
function
Displays an alert
box
Calling the
function
Prompt Box
A prompt box is often used if you want the user
to input a value before entering a page
When a prompt box pops up, the user will have
to click either "OK" or "Cancel" to proceed after
entering an input value
If the user clicks "OK" the box returns the input
value
If the user clicks "Cancel" the box returns null
Start of the
function
Prompt box
Calling the
function
Confirm Box
A confirm box is often used if you want the
user to verify or accept something
When a confirm box pops up, the user will
have to click either "OK" or "Cancel" to
proceed
If the user clicks "OK", the box returns true
If the user clicks "Cancel", the box returns
false
User input
confirmatio
n
Not confirmed
20
22
Window
Images[]
Array of
images
links[]
Array of
links
Element[ ]
Array of
element
of forms
Textboxes
buttons
select list
Reset
files
Forms[ ]
Array of
forms
Document
History
Location
anchors[]
Array of
anchors
Options[]
li
Navigator
23
document.forms[0].elements[0].value
document.images[0].src
document.links[0].href