javascript – ecmascript basics by satyen
TRANSCRIPT
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 1/21
By: Satyen Pandya
1
JavaScriptJavaScript ECMAScript BasicsECMAScript Basics
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 2/21
ContentsContents
2
Syntax, Variables, Keywords, Reserved Words
Primitive and Reference Values
Primitive Types
Conversions
Reference Types
Operators
Statements
Functions
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 3/21
SyntaxSyntax
3
ECMAScript basic concepts :
Everything is case-sensitive
Variables are loosely typed
End-of-line semicolons are optional
Comments are the same as in Java, C, Perl
Braces indicate code blocks
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 4/21
VariablesVariables
4
Variables are defined by var operator Variables do not require initialization like JAVA Variables can hold different types of values at
different times
Variable name First character must be letter, an underscore (_)\
or dollar sign ($) Remaining characters may be underscores, dollar
sings or any alphanumeric characters
Variable should follow Camel Notation (e.g. myTest, myVar) Pascal Notation (e.g. MyTest, MyVar) Hungarian Type Notation (e.g. sMyTest, bMyVar)
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 5/21
KeywordsKeywords
5
Keyword used to indicate beginning and/or ending
of statements
Keywords are reserved, can not use as variable
or function name
Few Keywords :
break do in thow
case else instanceof typeof
catch finally new var
continue for return void
default function switch while
delete if this with
try
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 6/21
Reserved WordsReserved Words
6
Word that are reserved for future use as keyword
Can not use as variable or function name
Few Reserved words :
abstrct enum int short
boolean export interface static
byte extends long super
char final native synchronized
class float package throws
const goto private transient
debugger implements protected Volatile
double import public
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 7/21
Primitive and Reference ValuesPrimitive and Reference Values
7
Primitive values - simple piece of data, stored on stack,
the value is stored directly in location that variable
accesses
Reference values - objects, stored in heap, the value is
stored in variable location pointer, where the object
is stored
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 8/21
Primitive TypesPrimitive Types
8
ECMAScript has five primitive types :
Undefined, Null, Boolean, Number, String
typeof Operator used to determine the type variables
value
typeof Operator takes one argument
typeof returns one of below value :
undefined, boolean, number, string, object
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 9/21
ConversionsConversions
9
Type conversion is a short, one-step process in
ECMAScript
Converting to a string : var.toString()
Converting to a number :
var a = parseInt(123);
var b = parseFloat(123.456);
Type Casting :
Boolean(value);
Number(value);String(value);
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 10/21
Reference TypesReference Types
10
They are referred as class, when you have a reference
value, you are dealing with an object
Objects are created by new operator and class name
e.g. var obj = new Object();
Few classes :
1. The Object class
2. The Boolean class
3. The Number class
4. The String class5. The instanceof operator
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 11/21
Reference Types (Contd)Reference Types (Contd)
11
The object class : base class for all ECMAScript classes
All the properties and methods of Object class also
present in other classes
Properties :
constructor
Prototype
Methods :
hasOwnProperty(property)
isPrototypeof(object) propertyIsEnumerable(property)
toString()
valueOf()
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 12/21
Reference Types (Contd)Reference Types (Contd)
12
The Boolean class : reference type for Boolean type
pass only Boolean value
toString() returns true or false
valueOf() returns true or false
The Number class : reference type for Number type
pass only Boolean value
toString() returns number primitive value
valueOf() returns number primitive value toFixed() returns string representation of number
toExponential returns e-notation string
toPrecision returns fixed or e-notation of number
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 13/21
Reference Types (Contd)Reference Types (Contd)
13
The String class : reference type for String type
pass only Boolean value
toString() returns string primitive value
valueOf() returns string primitive value
length gives number of characters
charAt() returns string containing character in position
charCodeAt() returns character code
concat() concate two or more strings
indexOf() returns position of given substring lastindexOf() returns last position of given substring
The instanceof operator : identifies the type of object
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 14/21
OperatorsOperators
14
Unary operators :
delete erases reference to an object property or
method
void returns undefined for any value
prefix increment/decrement (e.g. ++a, --a)
postfix increment/decrement (e.g. a++, a--)
unary plus returns exact same value for integer, for
string it converts them to numbers
unary minus returns negative value for integer, forstring it negates the value
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 15/21
Operators (Contd)Operators (Contd)
15
Bitwise operators :
Bitwise NOT tilde(~), it works in 3 stpes
1. Operand is converted to 32-bit number
2. Binary form converted into its ones complement
3. Ones complement is converted back to number
Bitwise AND ampersand(&)
works directly on the binary form of numbers
Bitwise OR pipe(|)
works directly on the binary form of numbers Bitwise XOR caret(^)
works directly on the binary form of numbers
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 16/21
Operators (Contd)Operators (Contd)
16
Bitwise operators :
Bit from FirstNumber Bit from SecondNumber A & B A | B A ^ B
1 1 1 1 0
1 0 0 1 1
0 1 0 1 1
0 0 1 0 0
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 17/21
Operators (Contd)Operators (Contd)
17
Boolean operators :
Logical NOT exclamation(!), always return Boolean
Logical AND double ampersand(&&)
Logical OR double pipe(||)
Operand 1 Operand 2 A && B A || B
true true true true
true false false truefalse true false true
false false false false
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 18/21
Multiplicative operatorsMultiplicative operators
18
Multiply : represented by asterisk(*)
Divide : represented by slash(/)
Modulus : represented by percent sign(%)
Additive operatorsAdditive operators
Add : represented by plus(+) Subtract : represented by minus(-)
Modulus : represented by percent sign(%)
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 19/21
Relational operatorsRelational operators
19
less-than : represented by <
greater-than : represented by >
less-than-or-equal : represented by <=
greater-than-or-equal : represented by >=
Equality operatorsEquality operators
Equal : represented by double equal sign (==)
Not Equal : represented by exclamation with equal sign
(!=)
Identically equal : three equal sign (===)
Not identically equal : exclamation and two equal (!==)
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 20/21
Conditional operatorsConditional operators
20
Syntax :Variable = boolean_expression ? true_value : false_value;
if expression is true then true_value will be assigned,
else false_value will be assigned
Assignment operatorsAssignment operators Simple assignment operator (=) assings the value on the
right to the variable on the left
Comma operatorsComma operators
more than one operation in single line
[email protected]@gmail.com
8/7/2019 JavaScript – ECMAScript Basics By Satyen
http://slidepdf.com/reader/full/javascript-ecmascript-basics-by-satyen 21/21
Thank youThank you
By: Satyen Pandya
[email protected]@gmail.com