You are on page 1of 23

1

TABLE OF CONTENTS
Java Script:................................................................................................................................................3
JavaScript name terminology:..............................................................................................................4
ECMA script:.........................................................................................................4
DOM level 0:.........................................................................................................5
Layers DOM:.........................................................................................................5
Proprietary DOM:..................................................................................................5
W3C DOM:............................................................................................................5
Mocha:..................................................................................................................5
LiveWire:..............................................................................................................5
LiveScript:.............................................................................................................5
JavaScript:............................................................................................................5
JavaScript1.0:.......................................................................................................6
JavaScript1.1:.......................................................................................................6
JavaScript1.2:.......................................................................................................6
JavaScript1.3:.......................................................................................................6
JavaScript1.4:.......................................................................................................6
JavaScript1.5:.......................................................................................................6
JavaScript2.0:.......................................................................................................6
Jscript:..................................................................................................................6
Active scripting:....................................................................................................6
JellyScript:.............................................................................................................6
InScript:................................................................................................................6
ECMAscript Mobile Profile:....................................................................................7
JavaScript family tree:..............................................................................................................................7
P.T.O..........................................................................................................................................................7

2
Lexical units:..............................................................................................................................................9
Identifiers:..............................................................................................................................................9
Identifier Rule:......................................................................................................9
Examples:2121212121212121212121212121212121212121212121212121212
121212121212121212121212121212121212121212121212121212121212121
2121212121212121212121212121212121212121212121.................................9
Keywords:............................................................................................................................................10
Keywords rule:....................................................................................................10
Examples:...........................................................................................................10
case:
...........................................................................................................................10
Reserved words:...................................................................................................................................14
Reserved words rules:........................................................................................15
Examples :..........................................................................................................15
export.................................................................................................................15
Syntax................................................................................................................15
Description.........................................................................................................15
import.................................................................................................................16
Syntax ...............................................................................................................16
Parameters ........................................................................................................16
Description ........................................................................................................16
Literals :..............................................................................................................................................17
Examples:...........................................................................................................17
Integer literals rules...........................................................................................17
Floating Point Literals rules................................................................................17
Boolean Literals..................................................................................................18
String Literals rules.............................................................................................18

3
Operators.............................................................................................................................................18
Examples:...........................................................................................................19
Arithmetic...........................................................................................................19
Assignment.........................................................................................................20
Comparison........................................................................................................20
Logical................................................................................................................21
String..................................................................................................................21
Examples............................................................................................................21
Comments:...........................................................................................................................................21
Creating Single Line Comments.........................................................................21
Examples:...........................................................................................................21
Display:...............................................................................................................22
Creating Multi-line Comments............................................................................22
Display:...............................................................................................................22
References:...............................................................................................................................................23

Java Script:
JavaScript is considered to be one of the most powerful scripting languages in use today. It is
often used for the development of client-side web development.[1] JavaScript is a prototype-based
scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm
language, supporting object-oriented,

imperative, and functional programming styles. JavaScript was

formalized in the ECMA Script language standard and is primarily used in the form of client-side
JavaScript, implemented as part of a Web browser in order to provide enhanced user interfaces and
dynamic websites. This enables programmatic access to computational objects within a host environment.
[2] JavaScript is one of the most well-known trademarks in the web development world; it is the

4
trademark of Sun Microsystems. It was originally invented by Netscape and was kept under license for
some time but now you are not required to get a license in order to use JavaScript. [1]

History:
When the World Wide Web was first created in the early 1990s all web pages were static. When
we viewed a web page we saw exactly what the page was set up to show us and there was no way for us
to interact with the page. So for the interaction with the web page there is need to something in response
to users action required the addition of some form of programming language to instruct the page. So thats
why Netscape was the first to introduce a programming language for that purpose that allow web pages to
become interactivecalled LiveScript later named as javaScript.[3] JavaScript was originally developed
by Brendan Eich of Netscape under the name Mocha, which was later renamed to LiveScript, and finally
to JavaScript mainly because it was more influenced by the Java programming language.[10][11] LiveScript
was the official name for the language when it first shipped in beta releases of Netscape Navigator 2.0 in
September 1995, but it was renamed JavaScript in a joint announcement with Sun Microsystems on
December 4, 1995,[12] when it was deployed in the Netscape browser version 2.0B3. [2] The change of
name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology
in its Netscape Navigator web browser. The final choice of name caused confusion, giving the impression
that the language was a spin-off of the Java programming language, and the choice has been characterized
by many as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new
web-programming language.[14][15] It has also been claimed that the language's name is the result of a comarketing deal between Netscape and Sun, in exchange for Netscape bundling Sun's Java runtime with its
then-dominant browser.
In November 1996, Netscape announced that it had submitted JavaScript to Ecma International for
consideration as an industry standard, and subsequent work resulted in the standardized version named
ECMAScript. [2]

JavaScript name terminology:


The hierarchy and evolution of javaScript name terminology is given below:
These names are subject to interpretation by the browser developers. For example, browsers may
support what they call JavaScript1.5, but not even support DHTML. This makes the JavaScript version
unreliable, do not rely on it.

ECMA script:

5
The core syntax for JavaScript, defining control structures, intrinsic objects and variable types,
operators, functions, scope, etc.

DOM level 0:
Says how to refer to forms, inputs, images, links and anchors as children of the document object.

Layers DOM:
Says how to refer to positioned elements (layers) and modify their style as children of the
document object with nested references.

Proprietary DOM:
Says how to refer to elements and modify their style using the all collection of the document or
parent object and the style child object of the element.

W3C DOM:
Says how to refer to elements and modify their style using various getElementBy... methods of the
document or parent object and the style child object of the element. Also says how to represent all
document elements as a tree structure. Also allows elements to be created, modified or deleted even after
the document has loaded.

Mocha:
An early name for JavaScript, not recognised by most browsers.

LiveWire:
An early name for JavaScript, not recognised by most browsers, used as the name of Netscape's
server side JavaScript.

LiveScript:
An early name for JavaScript, recognised by most browsers.

JavaScript:
A collective name for all versions of JavaScript.

JavaScript1.0:
The first version of JavaScript to be released - Early ECMAscript + DOM level 0 without images.

JavaScript1.1:
Early ECMAscript + DOM level 0.

JavaScript1.2:
ECMAscript + DOM level 0 + layers or proprietary DOM.

JavaScript1.3:
More advanced ECMAscript + DOM level 0 + layers or proprietary DOM.

JavaScript1.4:
Server side JavaScript.

JavaScript1.5:
Even more advanced ECMAscript + DOM level 0 + W3C DOM.

JavaScript2.0:
JavaScript 1.5 with several extensions added by Mozilla - may become a future standard.

Jscript:
Microsoft's JavaScript variations with extended core features.

Active scripting:
Microsoft's user friendly way of saying 'JScript'.

JellyScript:
WebTV's interpretation of JavaScript.

InScript:
iCab 3-'s interpretation of JavaScript.

ECMAscript Mobile Profile:


Parts of ECMAScript, basic JavaScript APIs, and DOM, all mixed together in a single
specification. Incompatible in far too many ways with existing pages on the Web, current browsers, the
ECMAScript specification, the DOM specifications, the JavaScript documentation, and other well
established practices. ECMAScript Mobile Profile should be ignored. It is harmful to the Web because of
its incompatibilities. [4]

JavaScript family tree:


P.T.O

FORTRAN (November 1954)

FORTRAN I (October 1956)

IAL (1958)

ALGOL 60 (1960)

CPL (1963)

8
Simula I (1964)

Simula 67 (1967)

BCPL (July 1967)

B (1969)

C (1971)

C (K & R) 1978

C with classes (April 1980)

C++ (July 1983)

ARM C++ (1989)

Classic C

ANSI C (C 89) 1989

ISO C (C 90) December 15, 1990

Cmm (1992)

LiveScript (1995)

JavaScript (December 1995)

JavaScript 1.5

JavaScript 2.0 (draft 1) February

9
18, 1999

JavaScript 2.0 (draft 4) April 26, 2002

Lexical units:
Identifiers:
JavaScript Identifiers are used to name the JavaScript language entities like variable, object,
function and to provide labels for certain loops in JavaScript code.

Identifier Rule:
A JavaScript identifier or name must start with a letter or underscore ("_"); subsequent characters
can also be digits (0-9). Letters include the characters "A" through "Z" (uppercase) and the characters "a"
through "z" (lowercase). JavaScript is case-sensitive. With some versions of JavaScript, dollar signs are
not legal in identifiers. The best practice of defining JavaScript Identifiers is to avoid the use of dollar
signs. You cant use JavaScript reserved keywords as a JavaScript Identifiers.

Examples:
o

Number_hits

temp99

_name

MyVar

Different types of java script identifiers are:

var intNum = 82
var PI = 3.14
var strInfo="This is a string"
var strGreet=Hello!;
var isMale=true
var arrAnimal={"cat","dog"}

10

Keywords:
Keywords rule:
Keywords are reserved and cannot be used as variable or function names. Here is the complete
list of JavaScript keywords:
break
case
continue
default
Delete
do
else
Export
False

for
function
if
Import
In
New
Null
return
switch

This
True
Typeof
var
Void
while
with

The underlined keywords are mostly used.

Examples:
break :
Break from executing the current loop, if more than one, break stops execution of the innermost
loop, handing control back to the next innermost. This example code never allows the value of x to exceed
8, despite the loop being able to run to 14.
x=0;
while (x<=14) {
if (x==8) {break;}
x++;
}
case:

Case is a keyword used to label compound statements within a switch statement.

switch (x) {
case 1 : {y=x;break;}

11
case 2 : {y=x;}
case 3 :
case 4 : {y=x;break;}
default : {y=0;break;}
}

Note that if x equals 2 or 3, the switch statement continues execution on to the case 4: statement where the
break statement stops further execution.

Continue :
Continue is used to restart the innermost loop.
x=1; y=1;
while (x<10) {
y++;
if (y==3) break;
else continue;
x++;
}
In this example, the x++ statement is never executed. At the end of the loop, x remains equal to one and y
is incremented to 3, at which point the loop reaches break before the continue can be executed. Note that
as x is never incremented, the loop must exit using break as the condition while (x<10) will never be met
and the loop becomes infinite - your Javascript program will be terminated.

default :
default is a keyword used in a switch statement usually as the last in a series of case statements.
The default case only executes if no case statement matches the value of the expression in the switch
statement.

do
JavaScript 1.2 only:
Use do to extend the function of the while loop. By default while doesn't execute any code within

12
the loop unless the while condition evaluates to true. If you need the code to execute ONCE even if the
while condition doesn't (yet) evaluate to true, use do to enclose the code:

x=1; y=1;
do {
y++;
if (y==3) break;
else continue;
x++;
}
while (x<10);

for :
Simple loops can use for to save code by initializing, testing and incrementing the test conditions
in one statement:
for (initialize ; test ; increment) {}
for (x=0;x<10;x++) {}
The loop executes repeatedly until the test condition evaluates to true. Initialization code is executed once
before the first evaluation of the test or the loop. The test condition is evaluated before each loop is
executed and the increment expression is executed only once the loop has completed (i.e. just before the
next test condition evaluation).

function
Functions are a way of executing compound statements in one HTML or Javascript call with the
extra flexibility of passing variables to the function.

function my_func(x,y,z) {

13
a=x+y-z;
alert(a);
}

This function can be called from HTML as:


<a href="javascript:my_func(10,2,3);">Test</a>
In this example, the alert box should show the result as 9.

if and else
Use if when a simple or compound statement must only be executed if certain variables are
already set to compatible values. The simplest if statement may be a test for division by zero:
a=4;
if (x!=0) {y=a/x;}

else :
Use else to catch instances where the preceding if test condition failed. else cannot be used except
immediately after the closing } of a valid if statement. In situations where if statements are nested inside
other if statements, the else statement will apply to if statement immediately preceding. Take care to put
your else statements beneath the correct} bracket.

a=4;
if (x!=0) {y=a/x;}
else { alert( "Division by zero attempted!" ); }

return:
Use return to stop execution of the current function and return control to the calling
function/procedure.
function my_func(x,y) {
return (x+y);
}

14

var sum = my_func(4,8);

In this example, the alert box should show the result as 12.

var :
Each variable in a function must be declared using var and optionally, var can be used to initialise
the variable. Variables defined outside functions can be declared without var.

x=0;
function my_func(x) {
var y=4;
x+=y;
}

while:
Simple loops can use while when the variable is already initialized but the contents of the while
loop must increment or update the variable(s) in the test condition.

var x=0;
while (x<10) {x++;}

The loop executes repeatedly until the test condition evaluates to false. The test condition is evaluated
before each loop is executed. Note the difference between for and while test conditions, for loops execute
until the test condition is true. while loops execute until the test condition is false.

Reserved words:
Reserved words for future use

15

Catch
Class
Const
Debugger
enum
extends

finally
super
Throw
Try
import
export

Reserved words rules:


A reserved word cannot be used

As a name in literal object notation

As a member name in dot notation

As a function argument

As a var

As an unqualified global variable

As a statement label

Examples :
export
Syntax
export name1, name2, ..., nameN;
export *;
Parameters
nameN
Property, function, or object to be exported.

Description

16
Typically, information in a signed script is available only to scripts signed by the same principals.
By exporting properties, functions, or objects, a signed script makes this information available to any
script (signed or unsigned). The receiving script uses the companion import statement to access the
information.
The first syntax exports the specified properties, functions, and objects.
The second syntax exports all properties, functions, and objects from the script.

import
Syntax
import objectName.name1, objectName.name2, ..., objectName.nameN;
import objectName.*;

Parameters
objectName
Name of the object that will receive the imported names.
nameN
Property, function, or object to be imported.

Description
The objectName parameter is the name of the object that will receive the imported names. For
example, if f and p have been exported, and if obj is an object from the importing script, the following
code makes f and p accessible in the importing script as properties of obj.
import obj.f, obj.p;
The first syntax imports the specified properties, functions, and objects from the exported script.
The second syntax imports all properties, functions, and objects from the exported script.

17

Literals :
JavaScript Literals are the notation for representing a fixed data value that appears directly in a
JavaScript program. JavaScript Literals helps us to assign values (initialize) to various JavaScript Data
Types and Variables; such as integers, floating-point numbers, strings, and Booleans; enumerated Data
Types and compound values such as arrays, records, and objects.

var intNum = 82 // 82 is a integer literal


var PI = 3.14

// 3.14 is a float literal

var strInfo="This is a string" // this is a string literal


var strGreet=Hello!; // another string literal
var isMale=true

// A Boolean value literal

var arrAnimal={"cat","dog"}

// array literals

Examples:
Integer literals rules
Integers can be expressed in decimal (base 10), hexadecimal (base 16), or octal (base 8) format. A
decimal integer literal consists of a sequence of digits (optionally suffixed as described below) without a
leading 0 (zero).
An integer can be expressed in octal or hexadecimal rather than decimal. A leading 0 (zero) on an integer
literal means it is in octal; a leading 0x (or 0X) means hexadecimal. Hexadecimal integers can include
digits (0-9) and the letters a-f and A-F. Octal integers can include only the digits 0-7.
Some examples of integer literals are:
0, 117 and -345 (decimal, base 10)
015, 0001 and -077 (octal, base 8)
0x1123, 0x00111 and -0xF1A7 (hexadecimal, "hex" or base 16)

Floating Point Literals rules

18
A floating-point literal can have the following parts:

A decimal integer which can be signed (preceded by "+" or "-"),

A decimal point ("."),

A fraction (another decimal number),

An exponent.

The exponent part is an "e" or "E" followed by an integer, which can be signed (preceded by "+" or "-").
A floating-point literal must have at least one digit and either a decimal point or "e" (or "E").
Some examples of floating point literals are:

3.1415

-3.1E12

.1e12

2E-12

Boolean Literals
The boolean type has two literal values: true and false.

String Literals rules


A string literal is zero or more characters enclosed in double (") or single (') quotes. A string must
be delimited by quotes of the same type; that is, either both single quotes and double quotes. The
following are examples of string literals:

"blah"

'blah'

"1234"

"one line \n another line"

Operators

19
The '+' operator is overloaded: it is used for string concatenation and arithmetic addition. This
may cause problems when inadvertently mixing strings and numbers. As a unary operator, it can convert a
numeric string to a number.

Examples:
// Concatenate 2 strings
alert('He' + 'llo'); // displays Hello
// Add two numbers
alert(2 + 6); // displays 8
// Adding a number and a string results in concatenation
alert(2 + '2');
// displays 22
alert('$' + 3 + 4); // displays $34, but $7 may have been expected
alert('$' + (3 + 4)); // displays $7
// Convert a string to a number
alert(+'2' === 2); // displays true
JavaScript language supports following type of operators.

Arithmetic
JavaScript supports the following binary arithmetic operators:
+

Addition

Subtraction

Multiplication

Division (returns a floating-point value)

Modulus (returns the integer remainder)

JavaScript supports the following unary arithmetic operators:


+

Unary conversion of string to number

Unary negation (reverses the sign)

++

Increment (can be prefix or postfix)

--

Decrement (can be prefix or postfix)

var x = 1;

20

alert(++x); // displays: 2
alert(x++); // displays: 2; x becomes 3 then
alert(x);

// displays: 3

alert(x); // displays: 2
alert(--x); // displays: 1
Assignment
=

Assign

+=

Add and assign

-=

Subtract and assign

*=

Multiply and assign

/=

Divide and assign

%=

Modulus and assign

Assignment of primitive types

var x = 1;
x *= 3;
alert(x); // displays: 3
x /= 3;
alert(x); // displays: 1
x -= 1;
alert(x); // displays: 0

Comparison
==

Equal

!=

Not equal

>

Greater than

>=
<
<=

Greater than or equal to


Less than
Less than or equal to

21
=== Identical (equal and of the same type)
!== Not identical

Logical
JavaScript provides four logical operators:

unary negation (NOT = !a)

binary disjunction (OR = a || b) and conjunction (AND = a && b)

ternary conditional (c ? t : f)

String
=

Assignment

Concatenation

+=

Concatenate and assign

Examples
str = "ab" + "cd"; // "abcd"
str += "e";
str2 = "2"+2

// "abcde"
// "22", not "4" or 4.

Comments:
Creating Single Line Comments
To create a single line comment in JavaScript, you place two slashes "//" in front of the code or
text you wish to have the JavaScript interpreter ignore. When you place these two slashes, all text to the
right of them will be ignored, until the next line.
These types of comments are great for commenting out single lines of code and writing small notes.

Examples:
<script type="text/javascript">

22
<!-// This is a single line JavaScript comment
document.write("I have comments in my JavaScript code!");
//document.write("You can't see this!");
//-->
</script>

Display:
I have comments in my JavaScript code!

Creating Multi-line Comments


Although a single line comment is quite useful, it can sometimes be burdensome to use when
disabling long segments of code or inserting long-winded comments. For this large comments you can use
JavaScript's multi-line comment that begins with /* and ends with */.
<script type="text/javascript">
<!-document.write("I have multi-line comments!");
/*document.write("You can't see this!");
document.write("You can't see this!");
document.write("You can't see this!");
document.write("You can't see this!");
document.write("You can't see this!");
document.write("You can't see this!");
document.write("You can't see this!");*/
//-->
</script>

Display:
I have multi-line comments! [5,6,7,8,9]

23

References:
[1] http://www.webopedia.com/TERM/J/Javascript.html
[2] http://en.wikipedia.org/wiki/JavaScript
[3] http://javascript.about.com/od/reference/a/history.htm
[4] http://www.howtocreate.co.uk/jshistory.html
[5] https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
[6] http://www.hscripts.com/tutorials/javascript/numbers.php
[7] http://www.codehelp.co.uk/html/jscript1.html
[8] http://www.tutorialspoint.com/javascript/javascript_operators.htm
[9] http://en.wikipedia.org/wiki/JavaScript_syntax#Operators
_____________________________________________________________________________________
_______________________________________________________________________________

You might also like