Title: http://www.slideshare.net/admecinstitute/java-script-basic
1JavaScript Basics
ADMEC MULTIMEDIA Leader in Animation Digital
Media Education ISO 90012008 CERTIFIED ADOBE
Testing Center www.admecindia.co.in
2Content
i. What is JavaScript? ii. Use of
JavaScript? iii. Features of JavaScript
Popups Variable Scopes
Function iv. DATATYPE in JavaScript
Number String
Undefined Boolean Null v.
Operators in JavaScript Assignment
Operator Equality Operator
Strict Equality Operators
3What is JavaScript?
JavaScript is scripting/programming language.
File Extension of JavaScript is ".js. This
extension can be catched by a number of
applications including Windows Script Host,
Dreamweaver MX, Notepad, Netscape Navigator,
PavScrip, UltraEdit. JavaScript is also
considered as "assembly language of the web".
JavaScript is totally user based. It is does not
store any in-built data or function. JavaScript
is object oriented. We can also create small
objects with help of basic JavaScript.
4Use of JavaScript?
JavaScript is also used to make websites rich and
dynamic. Almost every website have JavaScript
used in it. It tells how JavaScript important for
us. There are plenty of websites and
applications which are using JavaScript such as
Gmail, Google, YouTube, Yahoo, LinkedIn, Twitter,
Facebook etc...
5Features of JavaScript
- POPUPS
- Popup is additional display box/window
surprisingly comes over web browser with
information notice. - Alert Is any notice to the viewer provide only
option to "OK" after reading. - Example
- alert('welcome to js')
-
- Confirm It is useful to display any of
information/ message to viewer which let them
decide for accepting rejecting information with
option of "OK" "CANCEL - Example
- confirm('Are u sure to visit this page?')
-
6- Prompt Take input (info/text/massage/name--
alphabetic value) from Viewers. -
- Example
- prompt('Enter ur name plz')
7- VARIABLE
- Variable is a kind of container with limited
space where we can put value (Numeric, String,
Boolean true/false, objects etc) just for one
time if we try to put 2nd value 1st will
automatically eliminate. Variable can be
identified with unique names. - Variable are restricted with some special
characters (symbols) like we can only use
underscore (_), dollar () and Alpha Numeric
character. - The right way to write variables
- var myNum 45
- var my_num 55
- var num1 11
- var num 78
-
-
-
8SCOPES Scope is set of Variable, objects and
Function you can use. (Local Global) Maintain
accessibility through variable function.
There are 2 Variable used Local Variable
Global Variable In Local Scope, Variable is
declared within the Function whereas Global
Scope, Variable is Declared Outside the
function. Data remain secure if we used local
Variable.
9- FUNCTION
- A function is a group of reusable code which
enables a programmer to create a code that is in
better organization and execution and which can
be called anywhere in your program. In short
function eliminates the repetitive writing of
same codes. - Function helps a programmer to divide a big
program into a number of small chunks of program
and also helps in managing functions easily
effectively. - The most common way to define a function in
JavaScript is by using the keyword function. -
-
-
10- Syntax of function
- function main() //head of the function, these
brackets () are called parenthesis -
- //body of the function
-
-
- Types of function Named Function Anonymous
Function - Examples
- Named function
- function main()
-
-
- Note declared a 'main' function. The name of the
function is 'main'. -
-
-
11- Unnamed function
- var main function ()
-
-
-
- Note Declared an unnamed function and at the
same time assigned to a variable 'main'. You
can't declare a function without the name so you
need to store that in a variable. This type of
declaring method of function known as 'closure'
in JavaScript. -
-
12DATATYPE in JavaScript
- There 5 Primitive Datatypes given below
- Number
- A JavaScript programmer all the time have to
deal with numbers. It is a value and we use it in
various operations in the application or website.
Some times you can't get the expected result and
either your program gets broken or filled with
errors because of non-numeric types of values. - JavaScript offers main 3 functions to convert any
of the value to number. - Numbers can be written with or without decimals.
13Example var num 10.25 1. alert(Number(num))
//10.25 2. alert(parseInt(num))
//10 3. alert(parseFloat(num)) //10.25
- String
- String (value) is used to represent text related
data. String is also a set of element of 16-bit
unsigned integer value which start from the first
element is ZERO and the next is ONE and so on at
index. - We can use string literals in scripts by
enclosing them in single or double quotation
marks e.g. ( , ).
14Example Single Quotation Mark alert('you
clicked on CANCEL') Double Quotation
Mark alert("you clicked on \"OK\"") Note In
JavaScript, does not have a type to represent a
single character. To represent a single character
in JavaScript, we have to create a string that
contain only single character. A string that
contains empty string or zero characters ("") is
an empty or string with zero-length. String(value)
function can be used to convert any value to
string datatype.
15Undefined Undefined is a variable which
doesnt have any defined value. Example var
num // contains no value alert(num)// will get
undefined
16Boolean Boolean have two values i.e. true or
false or 1 or 0 and are logical
representative. Example if(confirm('Are you sure
to leave this page')) //you will be redirected
to the following URL if above condition is true
means if someone clicks on the OK
button window.location.href 'http//www.admecin
dia.co.in' else //nothing will happen if
someone clicks on CANCEL button as you will
receive false as the result return
false Note In above example you either get
True or False depends on the button you clicked
means you are getting a Boolean value.
17Null Null is exactly having single value when
Null is defined or nothing. Null is considered as
an object in JavaScript. var my_value
null alert(my_value 20) //0 Note 1. null
gets converted to the false boolean value and
i.e. 0 too 2. null and 'null' both are different
terms completely 3. null can be used when you
want to reset a variable or want to store
nothing
18 NOTE There are 2 other datatypes considered
according to ECMAScript standard. Symbol symbol
as in primitive datatype which are unique and
unchangeable. In some programming language they
are also called atoms. Object object data
type refers to the structure consist of data
information for working with the data.
19Operators in JavaScript
- Types of Operators
- Assignment Operator The equal sign () is called
Assignment Operators. - Equality Operator when double the equal sign
() is called Equality Operator. Is also
called comparison Operator. - Strict Equality Operators when Triple the equal
sign () is called Strict Equality Operator.
Is also called comparison Operator. -
-
20 Remark These are
just the basics of JavaScript and all these
topics play a vital role when you create
something using JavaScript. As much you are
familiar with these basics more you would be
strong in JavaScript.
21ADMEC MULTIMEDIA Leader in Animation
Digital Media Education ISO 90012008
CERTIFIED ADOBE Testing Center
ADMEC MULTIMEDIA INSTITUTE For
More information you can visit http//www.admeci
ndia.co.in
Contact Us ADMEC MULTIMEDIA INSTITUTEC-7/114,
IInd Floor, Sector- 7, Rohini, Delhi-
85Landmark Near Rohini East Metro
StationHelpline 1 91 9811 818 122Helpline
2 91 9911 782 350