Top Banner
JAVASCRIPT Prof. AshishSingh Bhatia
21
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Java script

JAVASCRIPT

Prof. AshishSingh Bhatia

Page 2: Java script

Brief History

December 4, 1995 Netscape and Sun introduced JavaScript 1.0, called LiveScript.

Netscape Navigator 2

LiveScript JavaScript

Microsoft joins in with IE 3 called it Jscript.

2

Prof. Ashish Bhatia

Page 3: Java script

What is JavaScript

Interpreted Language

Object-Based

Cross Platform

Loosely Typed

Multi Use Language

Client Side interpreted.

3

Prof. Ashish Bhatia

Page 4: Java script

Advantage of JavaScript

An Interpreted Language

Embedded within HTML

Minimal Syntax – Easy to learn

Quick Development

Design for Simple, Small Programs

Performance

Procedural Capabilities

Designed for Programming User Events

4

Prof. Ashish Bhatia

Page 5: Java script

Advantage of JavaScript

Easy Debugging and Testing

Platform Independence / Architectural Neutral

5

Prof. Ashish Bhatia

Page 6: Java script

How to add JS in HTML

<script language=“javascript”>Java Script Code

</script>

6

Prof. Ashish Bhatia

Page 7: Java script

Data Type

4 primitive data types

Number

Integer, Floating Number, NaN

Boolean

True and false [ 1 and 0 ]**

String

Null

A null , empty or nonexistent reference

Complex Types like array and objects

7

Prof. Ashish Bhatia

Page 8: Java script

Creating Variables and Array

var <variable name> = value; arrayName = new Array(); arrayName = new Array(length); Index starts with 0 join() and reverse() length

8

Prof. Ashish Bhatia

Page 9: Java script

Variable Name

Can Begin with

A to Z

a to z

_

$

Case Sensitive

variableName

9

Prof. Ashish Bhatia

Page 10: Java script

Operator

Prof. Ashish Bhatia

10

Arithmetic Operator

+ , - , * , / , % , ++ , --

Logical Operator

&&, || , !

Comparison Operator

== , === , != , !== , < , > , <= , >=

Assignment Operator

= , += , -= , *= , /= , %=

Page 11: Java script

Ternary Operator

Prof. Ashish Bhatia

11

Condition ? Value 1 : value 2

Special Operator

delete : Delete property of an object or an element at an array index

new : Create an instance of an Object type

void : Does not return a value.

Page 12: Java script

Programming Constructs

Prof. Ashish Bhatia

12

Assignment x = x+y;

Data declaration var x = 5;

If

Switch

While

For

Do while

Label LabelName: Statement

Page 13: Java script

Programming Constructs

Prof. Ashish Bhatia

13

break

continue

function call x = abs(y);

return

with with(Math){ }

delete delete a[5]

Method Invocation document.write(“Hello”);

Page 14: Java script

Functions in JavaScript

Prof. Ashish Bhatia

14

Built-in Function

eval() paresInt(), parseFloat()

User Defined Function

function function_name(parameter1, parameter2..)

{block of JavaScript Code

}

Page 15: Java script

Dialog Boxes

Prof. Ashish Bhatia

15

AlertUsed to display a small textual output with ok

button.

Prompt Displays a predefined message

Displays a text box and accepts user input

Display ok and cancel buttonOk text from text box is passed to the program

environment

Cancel passes NULL value to the program environment.

Page 16: Java script

Dialog Boxes

Prof. Ashish Bhatia

16

Confirm

Predefined message

OK and Cancel button

OK passes TRUE to the program

Cancel passes FALSE to the program

Page 17: Java script

Example of Alert

Prof. Ashish Bhatia

17

Page 18: Java script

Example of Alert

Prof. Ashish Bhatia

18

Page 19: Java script

Example of Alert

Prof. Ashish Bhatia

19

Page 20: Java script

Youtube channel

Prof. Ashish Bhatia

20

http://www.youtube.com/profashish

Page 21: Java script

Slideshare

Prof. Ashish Bhatia

21

http://www.slideshare.net/ashishsinghbhatia