SlideShare a Scribd company logo
1 of 40
Core Systems Transformation Solutions
Introduction to javaScript
Tutor: Maxim Maltsev, ROI
Confidential 2
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 3
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 4
Javascript: History
1995. Brendon Eich,
Netscape
1996. JScript.
Microsoft
1997.
ECMAScript
standard
1999.
ECMAScript
3 standard
Confidential 5
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 6
Javascript: Variables
var a;
var name = "simon";
var count = 6;
isInserted = false;
Confidential 7
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 8
Numbers
Strings
Booleans
Null
Undefined
Javascript: Types: Numbers
0.1 + 0.2 == 0.30000000000000004
Math.sin(3.5); var d = Math.PI * r * r;
> parseInt("123")
123
> + "42"
42
> parseInt("hello")
NaN
> isNaN(NaN)
true
> 1 / 0
Infinity
Confidential 9
Numbers
Strings
Booleans
Null
Undefined
Javascript: Types: Strings
Strings in JavaScript are sequences of
characters.
> "hello".length
5
> "hello".charAt(0)
h
> "hello, world".replace("hello", "goodbye")
goodbye, world
> "hello".toUpperCase()
HELLO
Confidential 10
Numbers
Strings
Booleans
Null
Undefined
Javascript: Types: Booleans
> Boolean("")
false
> Boolean(234)
true
false true
0
"“
NaN
null
undefined
all other values
Confidential 11
Numbers
Strings
Booleans
Null
Undefined
Javascript: Types: null
null is a value that indicates a deliberate
non-value
var a = null
Confidential 12
Numbers
Strings
Booleans
Null
Undefined
Javascript: Types: undefined
Undefined means not initialized!
var a;
a // undefined
var b={};
b.name // undefined
Confidential 13
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 14
Javascript: Operators
Assigning: =
var x = 5
Arithmetic: +, -, /, *, %
x = 3 + 5 // 8
Compound assignment: <operator> = <value>
x /= 4 // 2, mean x = x / 4
X += 5
X = X + 5
Confidential 15
Javascript: Operators
Comparisons: >,<, >=, <=, ==, !=, ===, !==
x == “2” // true, but
x === “2” // false
Logical: &&, ||, !
Confidential 16
Javascript: Operators
Some cases:
“3” + 4 + 5 // “345”
3 + 4 +”5” // “75”
true + 3 // 4
true + “3” // “true3”
false || 5 // 5
false || 0 || 5 || 3 // 5
Confidential 17
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 18
Javascript: Control Structures
if (condition1) {
//do something
} else if (condition2) {
//do something
} else {
//do something
}
for (statement 1; statement 2; statement 3) {
code block to be executed
}
for (x in person) {
// do something
}
while (condition) {
code block to be executed
}
do {
code block to be executed
} while (condition);
switch(expression) {
case n:
code block
break;
case n:
code block
break;
default:
default code block
}
Confidential 19
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 20
Javascript: Functions
function doSomething (parameters) {
code to be executed
}
var x = function (a, b) {return a * b};
x(5, 7)
(function () {
var x = "Hello!!"; // I will invoke myself
})();
Confidential 21
Javascript: Functions - this
Place of using Example This references to…
Outside functions this Global object, e.g window
Inside the regular function funcName(); Global object, e.g window
Inside a function by using
call / apply
func.call(obj);
func.apply(obj);
obj
Inside a function, using .
operator
someObject.func() someObj
Confidential 22
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 23
Javascript: Object
var obj = new Object();
var obj = {};
obj.width = 300;
obj[‘height’] = 200;
Confidential 24
Javascript: Object Instantiations
function Person (parameters) {
// constructor’s body goes here
}
var classInstance = new Person();
What happens here?
1. New object is created, its type is object
2. It set the internal prototype and constructor property to the same in the
function.
3. Constructor is executing with “this” pointing to the object
4. Result of the call becomes the new expression, if not defined, it points to the
object created in step 1
Confidential 25
Javascript: Object’s variables and methods
function Person(name){
this.name = name
}
Person.prototype.sayHi = function() {
return 'Hi, I am ' + this.name
}
var bob = new Person(‘Bob Newman’);
bob.sayHi();
Confidential 26
Javascript: Objects - Inheritance
function Person(name){
this.name = name;
}
Person.prototype.sayHi = function() {
return 'Hi, I am ' + this.name
}
function Employee(name){
Person.prototype.constructor.call(this, name);
}
Employee.prototype = new Person();
var bob = new Employee('Bob Newman');
bob.sayHi();
Confidential 27
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 28
Javascript: Scope
Global Variables
var myName = "Richard";
firstName = "Richard";
var name;
name;
Local Variables (Function-level scope)
var name = "Richard";
function showName () {
console.log (name); // undefined, beacause of value hoisting!
var name = "Jack"; // local variable; only accessible in this showName function
console.log (name); // Jack
}
console.log (name); // Richard: the global variable
Confidential 29
global
first
second
third
fourth
Javascript: Scope
function first(){
second();
function second(){
third();
function third(){
fourth();
function fourth(){
// do something
}
}
}
}
first();
Confidential 30
The Plan
Re-Introduction to Javascript
• History1
• Variables2
• Types3
• Operators4
• Control structures5
• Functions6
• Objects7
• Scope8
• Closures9
Confidential 31
Javascript: Closures
function makeAdder(a) {
return function(b) {
return a + b;
};
}
x = makeAdder(5);
y = makeAdder(20);
x(6)
?
y(7)
?
Confidential 32
Javascript: Thanks
Confidential 33
Arrays
Date
RegExp
Javascript: Appendix: Arrays
> var a = new Array();
> a[0] = "dog";
> a[1] = "cat";
> a[2] = "hen";
> a.length
3
> var a = ["dog", "cat", "hen"];
> a.length
3
Confidential 34
Javascript: Appendix : Arrays
> var a = ["dog", "cat", "hen"];
> a[100] = "fox";
> a.length
101
> typeof a[90]
undefined
Arrays
Date
RegExp
Confidential 35
Javascript: Appendix : Arrays
for (var i = 0; i < a.length; i++) {
// Do something with a[i]
}
for (var i in a) {
// Do something with i
}
Arrays
Date
RegExp
Confidential 36
Javascript: Appendix : Arrays
Method name Description
a.toString()
Returns a string with the toString() of each
element separated by commas.
a.toLocaleString()
Returns a string with the toLocaleString() of
each element separated by commas.
a.concat(item[, itemN])
Returns a new array with the items added on
to it.
a.join(sep)
Converts the array to a string - values delimited
by the sep param
a.pop() Removes and returns the last item.
a.push(item[, itemN]) Push adds one or more items to the end.
a.reverse() Reverse the array.
a.shift() Removes and returns the first item.
a.slice(start, end) Returns a sub-array.
a.sort([cmpfn]) Takes an optional comparison function.
a.splice(start, delcount[, itemN])
Lets you modify an array by deleting a section
and replacing it with more items.
a.unshift([item]) Prepends items to the start of the array.
Arrays
Date
RegExp
Confidential 37
Javascript: Appendix : Date
new Date();
new Date(value);
new Date(dateString);
new Date(year, month, day, hour, minute,
second, millisecond);
Arrays
Date
RegExp
Useful methods:
toString() – represent the date in the current local
format
parse() – convert the string to date
format() – format date to custom format
getTime() – get time in milliseconds
setTime() – set time in milliseconds
get/set Years, Date, Month, etc…
Confidential 38
Javascript: Appendix : RegExp
Literal and constructor notations are
possible:
/pattern/flags;
new RegExp(pattern [, flags]);
Two identical ways of creation:
/ab+c/i;
new RegExp("ab+c", "i");
Arrays
Date
RegExp
Confidential 39
Javascript: Appendix : RegExp
More examples can be found here:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
Method Description
exec
A RegExp method that executes a search for a match in a string. It
returns an array of information.
test
A RegExp method that tests for a match in a string. It returns true or
false.
match
A String method that executes a search for a match in a string. It returns
an array of information or null on a mismatch.
search
A String method that tests for a match in a string. It returns the index of
the match, or -1 if the search fails.
replace
A String method that executes a search for a match in a string, and
replaces the matched substring with a replacement substring.
split
A String method that uses a regular expression or a fixed string to break
a string into an array of substrings.
Arrays
Date
RegExp
Confidential 40
Javascript: Thanks

More Related Content

What's hot

IIUG 2016 Gathering Informix data into R
IIUG 2016 Gathering Informix data into RIIUG 2016 Gathering Informix data into R
IIUG 2016 Gathering Informix data into RKevin Smith
 
The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84Mahmoud Samir Fayed
 
Vasia Kalavri – Training: Gelly School
Vasia Kalavri – Training: Gelly School Vasia Kalavri – Training: Gelly School
Vasia Kalavri – Training: Gelly School Flink Forward
 
11.11.22 かなり役立つ競技プログラミング
11.11.22 かなり役立つ競技プログラミング11.11.22 かなり役立つ競技プログラミング
11.11.22 かなり役立つ競技プログラミングKei Nakazawa
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)Takayuki Goto
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolvedtrxcllnt
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftFlorent Pillet
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJSstefanmayer13
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptinjulkarnilesh
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in DepthC4Media
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwiftScott Gardner
 
Java8 stream
Java8 streamJava8 stream
Java8 streamkoji lin
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJavaSanjay Acharya
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++Andrey Karpov
 
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest
 
Reactive Programming with RxSwift
Reactive Programming with RxSwiftReactive Programming with RxSwift
Reactive Programming with RxSwiftScott Gardner
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowViliam Elischer
 
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleAxway Appcelerator
 

What's hot (20)

IIUG 2016 Gathering Informix data into R
IIUG 2016 Gathering Informix data into RIIUG 2016 Gathering Informix data into R
IIUG 2016 Gathering Informix data into R
 
The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84The Ring programming language version 1.2 book - Part 21 of 84
The Ring programming language version 1.2 book - Part 21 of 84
 
Vasia Kalavri – Training: Gelly School
Vasia Kalavri – Training: Gelly School Vasia Kalavri – Training: Gelly School
Vasia Kalavri – Training: Gelly School
 
11.11.22 かなり役立つ競技プログラミング
11.11.22 かなり役立つ競技プログラミング11.11.22 かなり役立つ競技プログラミング
11.11.22 かなり役立つ競技プログラミング
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
RxJS 5 in Depth
RxJS 5 in DepthRxJS 5 in Depth
RxJS 5 in Depth
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwift
 
Java8 stream
Java8 streamJava8 stream
Java8 stream
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJava
 
Towards hasktorch 1.0
Towards hasktorch 1.0Towards hasktorch 1.0
Towards hasktorch 1.0
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++
 
Lisp Primer Key
Lisp Primer KeyLisp Primer Key
Lisp Primer Key
 
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
CodeFest 2014. Axel Rauschmayer — JavaScript’s variables: scopes, environment...
 
Reactive Programming with RxSwift
Reactive Programming with RxSwiftReactive Programming with RxSwift
Reactive Programming with RxSwift
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrow
 
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL Module
 

Viewers also liked

An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptFahim Abdullah
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods pptkamal kotecha
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 

Viewers also liked (7)

Java script
Java scriptJava script
Java script
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 

Similar to Java Script Overview

Functional Programming In JS
Functional Programming In JSFunctional Programming In JS
Functional Programming In JSDamian Łabas
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverMongoDB
 
Adding To the Leaf Pile
Adding To the Leaf PileAdding To the Leaf Pile
Adding To the Leaf Pilestuporglue
 
Angular Weekend
Angular WeekendAngular Weekend
Angular WeekendTroy Miles
 
The Ring programming language version 1.4.1 book - Part 3 of 31
The Ring programming language version 1.4.1 book - Part 3 of 31The Ring programming language version 1.4.1 book - Part 3 of 31
The Ring programming language version 1.4.1 book - Part 3 of 31Mahmoud Samir Fayed
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsMatthew Beale
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript WidgetsKonstantin Käfer
 
Building a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationBuilding a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationJonathan Katz
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talkdesistartups
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3BeeNear
 
The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180Mahmoud Samir Fayed
 
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
 Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at... Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...Big Data Spain
 

Similar to Java Script Overview (20)

Functional Programming In JS
Functional Programming In JSFunctional Programming In JS
Functional Programming In JS
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
V8
V8V8
V8
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node Driver
 
Adding To the Leaf Pile
Adding To the Leaf PileAdding To the Leaf Pile
Adding To the Leaf Pile
 
Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
 
The Ring programming language version 1.4.1 book - Part 3 of 31
The Ring programming language version 1.4.1 book - Part 3 of 31The Ring programming language version 1.4.1 book - Part 3 of 31
The Ring programming language version 1.4.1 book - Part 3 of 31
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
 
Building a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationBuilding a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management Application
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3
 
The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
 Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at... Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
 

More from Return on Intelligence

Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Return on Intelligence
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsReturn on Intelligence
 
Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classificationReturn on Intelligence
 
Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)Return on Intelligence
 
Apache cassandra - future without boundaries (part2)
Apache cassandra - future without boundaries (part2)Apache cassandra - future without boundaries (part2)
Apache cassandra - future without boundaries (part2)Return on Intelligence
 
Apache cassandra - future without boundaries (part1)
Apache cassandra - future without boundaries (part1)Apache cassandra - future without boundaries (part1)
Apache cassandra - future without boundaries (part1)Return on Intelligence
 

More from Return on Intelligence (20)

Clean Code Approach
Clean Code ApproachClean Code Approach
Clean Code Approach
 
Code Coverage
Code CoverageCode Coverage
Code Coverage
 
Effective Communication in english
Effective Communication in englishEffective Communication in english
Effective Communication in english
 
Anti-patterns
Anti-patternsAnti-patterns
Anti-patterns
 
Conflicts Resolving
Conflicts ResolvingConflicts Resolving
Conflicts Resolving
 
Database versioning with liquibase
Database versioning with liquibaseDatabase versioning with liquibase
Database versioning with liquibase
 
Effective Feedback
Effective FeedbackEffective Feedback
Effective Feedback
 
English for Negotiations 2016
English for Negotiations 2016English for Negotiations 2016
English for Negotiations 2016
 
Lean Software Development
Lean Software DevelopmentLean Software Development
Lean Software Development
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!
 
Quick Start to AngularJS
Quick Start to AngularJSQuick Start to AngularJS
Quick Start to AngularJS
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.js
 
Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classification
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
Enterprise Service Bus
Enterprise Service BusEnterprise Service Bus
Enterprise Service Bus
 
Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)Apache cassandra - future without boundaries (part3)
Apache cassandra - future without boundaries (part3)
 
Apache cassandra - future without boundaries (part2)
Apache cassandra - future without boundaries (part2)Apache cassandra - future without boundaries (part2)
Apache cassandra - future without boundaries (part2)
 
Apache cassandra - future without boundaries (part1)
Apache cassandra - future without boundaries (part1)Apache cassandra - future without boundaries (part1)
Apache cassandra - future without boundaries (part1)
 
Career development in exigen services
Career development in exigen servicesCareer development in exigen services
Career development in exigen services
 
Introduction to selenium web driver
Introduction to selenium web driverIntroduction to selenium web driver
Introduction to selenium web driver
 

Recently uploaded

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Recently uploaded (20)

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

Java Script Overview

  • 1. Core Systems Transformation Solutions Introduction to javaScript Tutor: Maxim Maltsev, ROI
  • 2. Confidential 2 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 3. Confidential 3 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 4. Confidential 4 Javascript: History 1995. Brendon Eich, Netscape 1996. JScript. Microsoft 1997. ECMAScript standard 1999. ECMAScript 3 standard
  • 5. Confidential 5 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 6. Confidential 6 Javascript: Variables var a; var name = "simon"; var count = 6; isInserted = false;
  • 7. Confidential 7 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 8. Confidential 8 Numbers Strings Booleans Null Undefined Javascript: Types: Numbers 0.1 + 0.2 == 0.30000000000000004 Math.sin(3.5); var d = Math.PI * r * r; > parseInt("123") 123 > + "42" 42 > parseInt("hello") NaN > isNaN(NaN) true > 1 / 0 Infinity
  • 9. Confidential 9 Numbers Strings Booleans Null Undefined Javascript: Types: Strings Strings in JavaScript are sequences of characters. > "hello".length 5 > "hello".charAt(0) h > "hello, world".replace("hello", "goodbye") goodbye, world > "hello".toUpperCase() HELLO
  • 10. Confidential 10 Numbers Strings Booleans Null Undefined Javascript: Types: Booleans > Boolean("") false > Boolean(234) true false true 0 "“ NaN null undefined all other values
  • 11. Confidential 11 Numbers Strings Booleans Null Undefined Javascript: Types: null null is a value that indicates a deliberate non-value var a = null
  • 12. Confidential 12 Numbers Strings Booleans Null Undefined Javascript: Types: undefined Undefined means not initialized! var a; a // undefined var b={}; b.name // undefined
  • 13. Confidential 13 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 14. Confidential 14 Javascript: Operators Assigning: = var x = 5 Arithmetic: +, -, /, *, % x = 3 + 5 // 8 Compound assignment: <operator> = <value> x /= 4 // 2, mean x = x / 4 X += 5 X = X + 5
  • 15. Confidential 15 Javascript: Operators Comparisons: >,<, >=, <=, ==, !=, ===, !== x == “2” // true, but x === “2” // false Logical: &&, ||, !
  • 16. Confidential 16 Javascript: Operators Some cases: “3” + 4 + 5 // “345” 3 + 4 +”5” // “75” true + 3 // 4 true + “3” // “true3” false || 5 // 5 false || 0 || 5 || 3 // 5
  • 17. Confidential 17 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 18. Confidential 18 Javascript: Control Structures if (condition1) { //do something } else if (condition2) { //do something } else { //do something } for (statement 1; statement 2; statement 3) { code block to be executed } for (x in person) { // do something } while (condition) { code block to be executed } do { code block to be executed } while (condition); switch(expression) { case n: code block break; case n: code block break; default: default code block }
  • 19. Confidential 19 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 20. Confidential 20 Javascript: Functions function doSomething (parameters) { code to be executed } var x = function (a, b) {return a * b}; x(5, 7) (function () { var x = "Hello!!"; // I will invoke myself })();
  • 21. Confidential 21 Javascript: Functions - this Place of using Example This references to… Outside functions this Global object, e.g window Inside the regular function funcName(); Global object, e.g window Inside a function by using call / apply func.call(obj); func.apply(obj); obj Inside a function, using . operator someObject.func() someObj
  • 22. Confidential 22 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 23. Confidential 23 Javascript: Object var obj = new Object(); var obj = {}; obj.width = 300; obj[‘height’] = 200;
  • 24. Confidential 24 Javascript: Object Instantiations function Person (parameters) { // constructor’s body goes here } var classInstance = new Person(); What happens here? 1. New object is created, its type is object 2. It set the internal prototype and constructor property to the same in the function. 3. Constructor is executing with “this” pointing to the object 4. Result of the call becomes the new expression, if not defined, it points to the object created in step 1
  • 25. Confidential 25 Javascript: Object’s variables and methods function Person(name){ this.name = name } Person.prototype.sayHi = function() { return 'Hi, I am ' + this.name } var bob = new Person(‘Bob Newman’); bob.sayHi();
  • 26. Confidential 26 Javascript: Objects - Inheritance function Person(name){ this.name = name; } Person.prototype.sayHi = function() { return 'Hi, I am ' + this.name } function Employee(name){ Person.prototype.constructor.call(this, name); } Employee.prototype = new Person(); var bob = new Employee('Bob Newman'); bob.sayHi();
  • 27. Confidential 27 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 28. Confidential 28 Javascript: Scope Global Variables var myName = "Richard"; firstName = "Richard"; var name; name; Local Variables (Function-level scope) var name = "Richard"; function showName () { console.log (name); // undefined, beacause of value hoisting! var name = "Jack"; // local variable; only accessible in this showName function console.log (name); // Jack } console.log (name); // Richard: the global variable
  • 29. Confidential 29 global first second third fourth Javascript: Scope function first(){ second(); function second(){ third(); function third(){ fourth(); function fourth(){ // do something } } } } first();
  • 30. Confidential 30 The Plan Re-Introduction to Javascript • History1 • Variables2 • Types3 • Operators4 • Control structures5 • Functions6 • Objects7 • Scope8 • Closures9
  • 31. Confidential 31 Javascript: Closures function makeAdder(a) { return function(b) { return a + b; }; } x = makeAdder(5); y = makeAdder(20); x(6) ? y(7) ?
  • 33. Confidential 33 Arrays Date RegExp Javascript: Appendix: Arrays > var a = new Array(); > a[0] = "dog"; > a[1] = "cat"; > a[2] = "hen"; > a.length 3 > var a = ["dog", "cat", "hen"]; > a.length 3
  • 34. Confidential 34 Javascript: Appendix : Arrays > var a = ["dog", "cat", "hen"]; > a[100] = "fox"; > a.length 101 > typeof a[90] undefined Arrays Date RegExp
  • 35. Confidential 35 Javascript: Appendix : Arrays for (var i = 0; i < a.length; i++) { // Do something with a[i] } for (var i in a) { // Do something with i } Arrays Date RegExp
  • 36. Confidential 36 Javascript: Appendix : Arrays Method name Description a.toString() Returns a string with the toString() of each element separated by commas. a.toLocaleString() Returns a string with the toLocaleString() of each element separated by commas. a.concat(item[, itemN]) Returns a new array with the items added on to it. a.join(sep) Converts the array to a string - values delimited by the sep param a.pop() Removes and returns the last item. a.push(item[, itemN]) Push adds one or more items to the end. a.reverse() Reverse the array. a.shift() Removes and returns the first item. a.slice(start, end) Returns a sub-array. a.sort([cmpfn]) Takes an optional comparison function. a.splice(start, delcount[, itemN]) Lets you modify an array by deleting a section and replacing it with more items. a.unshift([item]) Prepends items to the start of the array. Arrays Date RegExp
  • 37. Confidential 37 Javascript: Appendix : Date new Date(); new Date(value); new Date(dateString); new Date(year, month, day, hour, minute, second, millisecond); Arrays Date RegExp Useful methods: toString() – represent the date in the current local format parse() – convert the string to date format() – format date to custom format getTime() – get time in milliseconds setTime() – set time in milliseconds get/set Years, Date, Month, etc…
  • 38. Confidential 38 Javascript: Appendix : RegExp Literal and constructor notations are possible: /pattern/flags; new RegExp(pattern [, flags]); Two identical ways of creation: /ab+c/i; new RegExp("ab+c", "i"); Arrays Date RegExp
  • 39. Confidential 39 Javascript: Appendix : RegExp More examples can be found here: https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Global_Objects/RegExp Method Description exec A RegExp method that executes a search for a match in a string. It returns an array of information. test A RegExp method that tests for a match in a string. It returns true or false. match A String method that executes a search for a match in a string. It returns an array of information or null on a mismatch. search A String method that tests for a match in a string. It returns the index of the match, or -1 if the search fails. replace A String method that executes a search for a match in a string, and replaces the matched substring with a replacement substring. split A String method that uses a regular expression or a fixed string to break a string into an array of substrings. Arrays Date RegExp

Editor's Notes

  1. JavaScript was created in 1995 by Brendan Eich, an engineer at Netscape, and first released with Netscape 2 early in 1996. Microsoft released a mostly-compatible version of the language called JScript with IE 3 several months later. Netscape submitted the language to Ecma International, a European standards organization, which resulted in the first edition of the ECMAScript standard in 1997. The standard received a significant update as ECMAScript edition 3 in 1999, and has stayed pretty much stable ever since.  JavaScript is an object oriented dynamic language; it has types and operators, core objects, and methods. Its syntax comes from the Java and C languages, so many structures from those languages apply to JavaScript as well. One of the key differences is that JavaScript does not have classes; instead, the class functionality is accomplished by object prototypes. The other main difference is that functions are objects, giving functions the capacity to hold executable code and be passed around like any other object.
  2. New variables in JavaScript are declared using the var keyword: var a; var name = "simon"; If you declare a variable without assigning any value to it, its type is undefined.  An important difference from other languages like Java is that in JavaScript, blocks do not have scope; only functions have scope. So if a variable is defined using var in a compound statement (for example inside an if control structure), it will be visible to the entire function.
  3. Numbers in JavaScript are "double-precision 64-bit format IEEE 754 values", according to the spec. This has some interesting consequences. There's no such thing as an integer in JavaScript, so you have to be a little careful with your arithmetic if you're used to math in C or Java. Watch out for stuff like: 0.1 + 0.2 == 0.30000000000000004 The standard numeric operators are supported, including addition, subtraction, modulus (or remainder) arithmetic and so forth. There's also a built-in object that I forgot to mention earlier called Math to handle more advanced mathematical functions and constants: Math.sin(3.5); var d = Math.PI * r * r; You can convert a string to an integer using the built-in parseInt() function. This takes the base for the conversion as an optional second argument, which you should always provide: > parseInt("123", 10) 123 > parseInt("010", 10) 10 If you don't provide the base, you can get surprising results in older browsers (pre-2013): > parseInt("010") 8 That happened because the parseInt function decided to treat the string as octal due to the leading 0. If you want to convert a binary number to an integer, just change the base: > parseInt("11", 2) 3 Similarly, you can parse floating point numbers using the built-in parseFloat() function which uses base 10 always unlike itsparseInt() cousin. You can also use the unary + operator to convert values to numbers: > + "42" 42
  4. Strings Strings in JavaScript are sequences of characters. More accurately, they're sequences of Unicode characters, with each character represented by a 16-bit number. This should be welcome news to anyone who has had to deal with internationalisation. If you want to represent a single character, you just use a string of length 1. To find the length of a string, access its length property: > "hello".length 5 There's our first brush with JavaScript objects! Did I mention that you can use strings like objects too? They have methods as well: > "hello".charAt(0) h > "hello, world".replace("hello", "goodbye") goodbye, world > "hello".toUpperCase() HELLO
  5. JavaScript has a boolean type, with possible values true and false (both of which are keywords). Any value can be converted to a boolean according to the following rules: false, 0, the empty string (""), NaN, null, and undefined all become false all other values become true You can perform this conversion explicitly using the Boolean() function: > Boolean("") false > Boolean(234) true However, this is rarely necessary, as JavaScript will silently perform this conversion when it expects a boolean, such as in an if statement (see below). For this reason, we sometimes speak simply of "true values" and "false values," meaning values that become true and false, respectively, when converted to booleans. Alternatively, such values can be called "truthy" and "falsy", respectively. Boolean operations such as && (logical and), || (logical or), and ! (logical not) are supported; see below.
  6. JavaScript distinguishes between null, which is a value that indicates a deliberate non-value, and undefined, which is a value of type 'undefined' that indicates an uninitialized value — that is, a value hasn't even been assigned yet. We'll talk about variables later, but in JavaScript it is possible to declare a variable without assigning a value to it. If you do this, the variable's type is undefined.
  7. JavaScript distinguishes between null, which is a value that indicates a deliberate non-value, and undefined, which is a value of type 'undefined' that indicates an uninitialized value — that is, a value hasn't even been assigned yet. We'll talk about variables later, but in JavaScript it is possible to declare a variable without assigning a value to it. If you do this, the variable's type is undefined.
  8. JavaScript's numeric operators are +, -, *, / and % - which is the remainder operator. Values are assigned using =, and there are also compound assignment statements such as += and -=. These extend out to x = x operator y. x += 5 x = x + 5 You can use ++ and -- to increment and decrement respectively. These can be used as prefix or postfix operators. The + operator also does string concatenation: > "hello" + " world" hello world If you add a string to a number (or other value) everything is converted in to a string first. This might catch you up: > "3" + 4 + 5 "345" > 3 + 4 + "5" "75" Adding an empty string to something is a useful way of converting it. Comparisons in JavaScript can be made using <, >, <= and >=. These work for both strings and numbers. Equality is a little less straightforward. The double-equals operator performs type coercion if you give it different types, with sometimes interesting results: > "dog" == "dog" true > 1 == true true To avoid type coercion, use the triple-equals operator: > 1 === true false > true === true true There are also != and !== operators. JavaScript also has bitwise operations. If you want to use them, follow the link below. https://developer.mozilla.org/en/JavaScript/Reference/Operators/Bitwise_Operators
  9. JavaScript's numeric operators are +, -, *, / and % - which is the remainder operator. Values are assigned using =, and there are also compound assignment statements such as += and -=. These extend out to x = x operator y. x += 5 x = x + 5 You can use ++ and -- to increment and decrement respectively. These can be used as prefix or postfix operators. The + operator also does string concatenation: > "hello" + " world" hello world If you add a string to a number (or other value) everything is converted in to a string first. This might catch you up: > "3" + 4 + 5 "345" > 3 + 4 + "5" "75" Adding an empty string to something is a useful way of converting it. Comparisons in JavaScript can be made using <, >, <= and >=. These work for both strings and numbers. Equality is a little less straightforward. The double-equals operator performs type coercion if you give it different types, with sometimes interesting results: > "dog" == "dog" true > 1 == true true To avoid type coercion, use the triple-equals operator: > 1 === true false > true === true true There are also != and !== operators. JavaScript also has bitwise operations. If you want to use them, follow the link below. https://developer.mozilla.org/en/JavaScript/Reference/Operators/Bitwise_Operators
  10. JavaScript's numeric operators are +, -, *, / and % - which is the remainder operator. Values are assigned using =, and there are also compound assignment statements such as += and -=. These extend out to x = x operator y. x += 5 x = x + 5 You can use ++ and -- to increment and decrement respectively. These can be used as prefix or postfix operators. The + operator also does string concatenation: > "hello" + " world" hello world If you add a string to a number (or other value) everything is converted in to a string first. This might catch you up: > "3" + 4 + 5 "345" > 3 + 4 + "5" "75" Adding an empty string to something is a useful way of converting it. Comparisons in JavaScript can be made using <, >, <= and >=. These work for both strings and numbers. Equality is a little less straightforward. The double-equals operator performs type coercion if you give it different types, with sometimes interesting results: > "dog" == "dog" true > 1 == true true To avoid type coercion, use the triple-equals operator: > 1 === true false > true === true true There are also != and !== operators. JavaScript also has bitwise operations. If you want to use them, follow the link below. https://developer.mozilla.org/en/JavaScript/Reference/Operators/Bitwise_Operators
  11. JavaScript has a similar set of control structures to other languages in the C family. Conditional statements are supported by if and else; you can chain them together if you like: If you don't add a break statement, execution will "fall through" to the next level.
  12. Along with objects, functions are the core component in understanding JavaScript. The most basic function couldn't be much simpler: function add(x, y) { var total = x + y; return total; } This demonstrates everything there is to know about basic functions. A JavaScript function can take 0 or more named parameters. The function body can contain as many statements as you like, and can declare its own variables which are local to that function. The return statement can be used to return a value at any time, terminating the function. If no return statement is used (or an empty return with no value), JavaScript returns undefined.
  13. JavaScript objects can be thought of as simple collections of name-value pairs. As such, they are similar to: Dictionaries in Python Hashes in Perl and Ruby Hash tables in C and C++ HashMaps in Java Associative arrays in PHP
  14. What happens here?
  15. What happens here?
  16. What happens here?
  17. Local: Unlike most programming languages, JavaScript does not have block-level scope (variables scoped to surrounding curly brackets); instead, JavaScript has function-level scope. Variables declared within a function are local variables and are only accessible within that function or by functions inside that function. If you declare a global variable and a local variable with the same name, the local variable will have priority when you attempt to use the variable inside a function (local scope) Global: It is important to note that all global variables are attached to the window object. So, all the global variables we just declared can be accessed on the window object If a variable is initialized (assigned a value) without first being declared with the var keyword, it is automatically added to the global context and it is thus a global variable
  18. What happens here?
  19. Whenever JavaScript executes a function, a 'scope' object is created to hold the local variables created within that function. It is initialised with any variables passed in as function parameters. This is similar to the global object that all global variables and functions live in, but with a couple of important differences: firstly, a brand new scope object is created every time a function starts executing, and secondly, unlike the global object (which is accessible as this and in browsers is accessible as window) these scope objects cannot be directly accessed from your JavaScript code. There is no mechanism for iterating over the properties of the current scope object, for example. So when makeAdder is called, a scope object is created with one property: a, which is the argument passed to the makeAdder function. makeAdder then returns a newly created function. Normally JavaScript's garbage collector would clean up the scope object created for makeAdder at this point, but the returned function maintains a reference back to that scope object. As a result, the scope object will not be garbage collected until there are no more references to the function object that makeAdder returned.
  20. Arrays in JavaScript are actually a special type of object. They work very much like regular objects (numerical properties can naturally be accessed only using [] syntax) but they have one magic property called 'length'. This is always one more than the highest index in the array. The old way of creating arrays is as follows:
  21. Note that array.length isn't necessarily the number of items in the array. Consider the following: Remember — the length of the array is one more than the highest index. If you query a non-existent array index, you get undefined
  22. This is slightly inefficient as you are looking up the length property once every loop. An improvement is this: for (var i = 0, len = a.length; i < len; i++) { // Do something with a[i] } An even nicer idiom is: for (var i = 0, item; item = a[i++];) { // Do something with item } Here we are setting up two variables. The assignment in the middle part of the for loop is also tested for truthfulness — if it succeeds, the loop continues. Since i is incremented each time, items from the array will be assigned to item in sequential order. The loop stops when a "falsy" item is found (such as undefined). Note that this trick should only be used for arrays which you know do not contain "falsy" values (arrays of objects or DOM nodes for example). If you are iterating over numeric data that might include a 0 or string data that might include the empty string you should use the i, len idiom instead. Another way to iterate is to use the for...in loop. Note that if someone added new properties to Array.prototype, they will also be iterated over by this loop:
  23. Note: Note that JavaScript Date objects can only be instantiated by calling JavaScriptDate as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object; unlike other JavaScript object types, JavaScript Date objects have no literal syntax. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
  24. The literal notation provides compilation of the regular expression when the expression is evaluated. Use literal notation when the regular expression will remain constant. For example, if you use literal notation to construct a regular expression used in a loop, the regular expression won't be recompiled on each iteration. The constructor of the regular expression object, for example, new RegExp("ab+c"), provides runtime compilation of the regular expression. Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input.
  25. The literal notation provides compilation of the regular expression when the expression is evaluated. Use literal notation when the regular expression will remain constant. For example, if you use literal notation to construct a regular expression used in a loop, the regular expression won't be recompiled on each iteration. The constructor of the regular expression object, for example, new RegExp("ab+c"), provides runtime compilation of the regular expression. Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input.