SlideShare a Scribd company logo
1 of 43
JavaScript
Presented by Team KAF
San Jose State University
Department of Computer Science
CS152 Spring 2014 May 5th
1. Introduction to JavaScript
2. Object Oriented JavaScript
3. Data Types and Data Structures and Control
Statements
4. Functions
5. Reference
Agenda
Introduction to Javascript
• What is JavaScript
• History
• Cores
• Today’s JavaScript
• Features in Programming Paradigm
 a dynamic computer language
 (initially)Client side of programming language
 First released in 1995
What is JavaScript?
 Developed by Brendan Eich in Netscape communications
 influenced by Shceme, self, Java, C, Python, AWK,
HyperTalk
 At 1996, Internet Explorer3.0 can run JavaScript
 As the internet and web became popular, JavaScript
become to play an important rule to enrich their website.
 At 2005, Microsoft developed AJAX (JS and XML)
 It becomes more popular language to develop web
applications.
History of JavaScript
 ECMAScript: the scripting language standardized by Ecma
International to reduce a compatible dialects of the
language between Netscape and Microsoft.
 Document Object Model (DOM) : provide supports for
HTML and XML documents
 Browser Object Model (BOM) : a set of objects related to
the bowser environment primarily utilized in HTML5
3 cores of JavaScript
 Create rich and powerful web applications
 Write server-side code using .NET or Node.js
As well as code that can run using Rhino(JS engine written in
java )
 Create Mobile Applications
 Run on iPhone, Android and other phones
 using PhoneGap or Titanium
 Full-Stack for web application (UI-DB) by One Language
 Especially MEAN stack
Today’s JavaScript
Features in Paradigm
JavaScript
 Script language
 Prototype Based
 Objected Oriented
 Procedural
 Functional
 Dynamic Type Checking
 Weakly Typed
 On web browsers
Java
 Complied language
 Class Based
 Objected Oriented
 Procedural
 Static Type Checking
 Strong Typed
 On JVM
Cont: Features in Paradigm
JavaScript
 Less Reliable
 Weakly typed, unchecked
parameters
 Regularity
 Generality
 Orthogonal
 Uniformity
 Efficiency
 Less: type checked at runtime
 Extensibility
 More: libraries and frameworks
 Node.js, Angluer.js, Backbone.js.
 Jquery , React….etc
Java
 More Reliable
 Strong type, parameters
checked
 Regularity
 Generality
 Orthogonal
 Uniformity
 Efficiency
 More: type checked by compiler
 Extensibility
 Less: libraries and frameworks
Object Oriented JavaScript
 JavaScript is an object based language
 Objects can store multiple properties.
 Example
var fruit = “apple”;
var fruit = {type: “apple”, color: “red”, brand: “Fuji”}
Objects
 JavaScript is a prototype based objected oriented
language
 Which means that inheritance is performed by prototypes,
rather than extending their functionalities in a place
 Inheritance
 Objects inherit from other objects since JavaScript does not
have an idea of “class.”
 When an object inherits from another object, it usually adds
new methods to the inherited ones. Therefore, extending
the old objects.
Objected oriented JavaScript
Example of inheritance
JavaScript
function Animal(name){
this.name = name;
}
Animal.prototype.speak = funciton(){
console.log(“my name is ” + this.name);
};
var animal = new Animal(‘Monty’);
animal.speak(); //My name is Monty
function Cat(name){
Animal.call(this, name);
}
Cat.prototype = new Animal();
var cat = new Cat(‘Monty’);
Cat.speak(); //My name is Monty
java
Public class Animal(){
Public Animal(name){
this.name = name;
} }//Animal
Public class Cat(name) extends Animal{
super(name);
}//Cat
Cat cat = new Cat(‘Monty’);
 Primary difference between “class based” OO and
“prototype based” OO is: Prototype based does not
have classes.
Prototypes
Prototypes
JavaScript
function fruit(type, color, brand)
{
this.type = type;
this.color = color;
this.brand = brand;
}
var apple = new fruit(“apple”,
“red”, “Fuji”);
java
public class Fruit(){
Fruit(str type, str color, str brand ) {
this.type = type;
this.color = color;
this.brand = brand; }
}//class
Fruit apple = new Fruit(“apple”,
“red”, “Fuji”);
Treat “class” in java
as a function in JS.
 Encapsulation consists mainly of packing data into
objects because there is no classes in JS.
 prototyping is a common practice when enforcing
encapsulation, as it allows for many object attributes
and methods to be localized into a single object.
Encapsulation
 The capability to combine several objects into a new,
more complex object is a functionality that JS
supports.
 An example:
var fruit = {type: “apple”, color: “red”, brand: “Fuji”}
Aggregation
Data types and Data Structures
and Control Statements
 Number
 String
 Booleans
 Array
 Object
 Undefined
 Null
Data Type
TIPS!
In JavaScript, undefined and Null are
different.
Null is an Object meaning it does not
exists. While, undefined is value for a
valuable without value.
Number object supports
Both double and int
in java
Primitive Types
 Dynamically typed
var y
y = 8l
x = 21
var newStr = “hello”;
 Case Sensitive
var randFruit = “apple”;
var randfruit = “apple”;
Variables
They are two
unique
variables
Declaring a variable without
“var” notation will have global
scope by default. With “var”
notation, localize the scope of
variable.
Which implies, JS
supports both global
and local variables
 Functions is not checked the number of parameters.
function f(x, y) {// body }
can call f(x,y) by all of the following:
f();
f(1);
f(3,true);
Undefined
Programmer’s response to
make sure and pay attention
to preconditions of function!
All do not give you
ERROR!
Errors Caught by
Compiler
(checked)
Errors Caught by
Runtime
(unchecked)
Errors Caught by
Nothing
(Less Reliable)
All Program Errors
 To check the pre-condition, and to reveal errors as quickly
as possible. You can use undefined!
function f(x)
{
if(typeof x == “undefined”){
// not set! Missing parameter or something!
x = 0; //make it default here!
}//if
else{//good to go the next!}//else
} //f
Undefined: check pre-condition
 Supports major basic arithmetic operators{+,-,/,*}.
 Also some syntactic sugars.
var a = 123;
var b = ++a;
Result  a = 124, b = 124
var c = 123;
var d = c--;
Result  c =122, d = 123
Operators
Same as Java!
String Conversion
 Number like string, js
convers to a number
automatically.
 Can operate arithmetic
on the string except
addition.
 Inverse operation is done
by concatenating
var n = “1”;
n = n * 5
type of n;
----Inverse Operation------------
var n = 1;
n = “” + n;
type of n;
String type
String * numerical
Number!
Number type
String + number
String
 Supports comparison symbols that java supports
 Also, Operator symbol === to return true if both operands
are equal AND the same type
 Example
1 === “ 1”  false because of type
1 === 1  true
1 !== 1  false
1 !== ‘1’  true because of type
Comparisons
Equals == Not equals !=
Less < More >
Less Equals <= More Equals >=
Point:
Equals ==
And equals value
and type === are
not the same!!!
 Declaration of array:
 Use [] surrounding your elements
var arr = [1, “2”, 3, “4” ];
 Access to the element
arr[2] = “three” ;
arr = [1, “2”, “three”, “4” ] ;
 Add data: address an index where the outside of
current boundary.
var arr = [1,2,3];
arr[4] = “4th”
arr = [1,2,3, undefined, “four”]
Arrays
Unlike java, can put any type
in one array
 Delete Elements: JS has delete operator.
var arr = [1,2,3];
delete arr[1];
arr = [1, undefined, 3]
Cont: Arrays
But, it does not change
its size…..
Control Structures: if-statement
Conventional
var result = (a === 2) ? “a is two”:
“a is not two”;
Ordinary
if(a === 2)
{
result = “a is two”;
}
else
{
result = “a is not two” ;
}
JavaScript also supports
Switch-statement!
Loops
 4 types of loop
 While loop
 Do-while loop
 For loop
 For –in loop
 For – in Loop
var a = [‘a’, ‘b’, ‘c’];
var result = ‘n’;
for(var i in a )
{
result += “index” + i + “, value” + a[i]+ ‘n’;
}
Functions
 Declare function as below:
function fucntionName() {
//what to do
}
function functionName1(x){
//to do
}
function f(x, y ,z){
//do
}
Function
 JavaScript passes values by Reference or by value
 Primitive types, such as Numbers, String, Boolean are
passed by Value
 Changes in function not-directly affect to the original value.
 Object and Array are passed by Reference
 Changes in functions directly affect to the original value.
Pass By…
Function
 Functional Programming
Paradigm treat a function
as the first class object.
 Can assign function to
variable.
 Can pass function as
parameters
 Can return function
function sum(x,y){
return a + b;
}
var newSum = sum;
newSum (1,2); Result: 3
---------------------------------------------------------------------
Data Representations
 Json: stands for JS Object Notation.
 a lightweight Data Interchange format.
 Interchangeable between two different machine(big endian,
little endian, etc)
 Data Processing format.
 use the format to store variables that is used in programs
 Data Storage format: can store json into DB directly.
 Self-contained format (able to adjust changes)
 Data explain data itself.
 JSON is used interchange and process and store.
 Example actual products are Mongo DB, Open
Data(Whether,,,etc)
Json
Json Many APIs are available to
read/write/parse Json.
Demo Program
 JavaScript (of course!)
 jQuery: jQuery is a fast, small, and featured-rich JS library.
It makes things like HTML doc traversal and manipulation,
event handling, animation and Ajax much simpler with an
easy to use API that works across a multitude of browsers.
 Ajax: stands for asynchronous JS and XML.
 With Ajax, web applications can send data to and retrieve
from a server asynchronously(in the background) without
interfering with the display and behavior of the existing page.
 Json
Demo Program Used
 Object-Oriented JavaScript - Second Edition
 By: Stoyan Stefanov; Kumar Chetan Sharma
 Publisher: Packt Publishing
 Pub. Date: July 26, 2013
 JavaScript Programmer's Reference
 By: Jonathan Reid; Thomas Valentine
 Publisher: Apress
 Pub. Date: June 05, 2013
Reference
 Modern JavaScript Develop and Design
 By: Larry Ullman
 Publisher: Packt Publishing
 Pub. Date: Feb 17, 2012
Reference
Question and Answer!

More Related Content

What's hot (20)

Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Javascript
JavascriptJavascript
Javascript
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java script
Java scriptJava script
Java script
 
3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java script basics
Java script basicsJava script basics
Java script basics
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Javascript
JavascriptJavascript
Javascript
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Javascript
JavascriptJavascript
Javascript
 
An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScript
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Java script
Java scriptJava script
Java script
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 

Viewers also liked

TechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTech CBT
 
Başarılı ve başarısız girişimci myspace vs. facebook
Başarılı ve başarısız girişimci   myspace vs. facebookBaşarılı ve başarısız girişimci   myspace vs. facebook
Başarılı ve başarısız girişimci myspace vs. facebookMerve Ülkü
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutesSimon Willison
 

Viewers also liked (6)

TechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in Depth
 
Başarılı ve başarısız girişimci myspace vs. facebook
Başarılı ve başarısız girişimci   myspace vs. facebookBaşarılı ve başarısız girişimci   myspace vs. facebook
Başarılı ve başarısız girişimci myspace vs. facebook
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 

Similar to javascript

Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript BootcampAndreCharland
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayChamnap Chhorn
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascriptRobbin Zhao
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascriptMD Sayem Ahmed
 
Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Sopheak Sem
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfSreeVani74
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingRadoslav Georgiev
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Learn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netLearn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netwww.myassignmenthelp.net
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTAAFREEN SHAIKH
 

Similar to javascript (20)

Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 
JavaScript in Object-Oriented Way
JavaScript in Object-Oriented WayJavaScript in Object-Oriented Way
JavaScript in Object-Oriented Way
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
chap04.ppt
chap04.pptchap04.ppt
chap04.ppt
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 
Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02Javascriptinobject orientedway-090512225827-phpapp02
Javascriptinobject orientedway-090512225827-phpapp02
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Java Script Introduction
Java Script IntroductionJava Script Introduction
Java Script Introduction
 
Oop java
Oop javaOop java
Oop java
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
 
JavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft TrainingJavaScript Basics - GameCraft Training
JavaScript Basics - GameCraft Training
 
Java script summary
Java script summaryJava script summary
Java script summary
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Javascript analysis
Javascript analysisJavascript analysis
Javascript analysis
 
Learn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.netLearn ActionScript programming myassignmenthelp.net
Learn ActionScript programming myassignmenthelp.net
 
Java
JavaJava
Java
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 

More from Kaya Ota

Solr 勉強会 20191028
Solr 勉強会 20191028Solr 勉強会 20191028
Solr 勉強会 20191028Kaya Ota
 
Privacy statement
Privacy statementPrivacy statement
Privacy statementKaya Ota
 
CS166 Final project
CS166 Final projectCS166 Final project
CS166 Final projectKaya Ota
 
Cs166 mynote
Cs166 mynoteCs166 mynote
Cs166 mynoteKaya Ota
 
Edited keeping happiness
Edited keeping happinessEdited keeping happiness
Edited keeping happinessKaya Ota
 
Database Management System Review
Database Management System ReviewDatabase Management System Review
Database Management System ReviewKaya Ota
 
Math178 hw7
Math178 hw7Math178 hw7
Math178 hw7Kaya Ota
 
CS152 Programming Paradigm
CS152 Programming Paradigm CS152 Programming Paradigm
CS152 Programming Paradigm Kaya Ota
 
Umap traversabilityin graph
Umap traversabilityin graphUmap traversabilityin graph
Umap traversabilityin graphKaya Ota
 
Price Distribution and Consumer Surplus
Price Distribution and Consumer Surplus Price Distribution and Consumer Surplus
Price Distribution and Consumer Surplus Kaya Ota
 
Midterm review for CS156
Midterm review for CS156Midterm review for CS156
Midterm review for CS156Kaya Ota
 
Jit complier
Jit complierJit complier
Jit complierKaya Ota
 
Methodologies of Software Engineering
Methodologies of Software EngineeringMethodologies of Software Engineering
Methodologies of Software EngineeringKaya Ota
 

More from Kaya Ota (14)

Solr 勉強会 20191028
Solr 勉強会 20191028Solr 勉強会 20191028
Solr 勉強会 20191028
 
Privacy statement
Privacy statementPrivacy statement
Privacy statement
 
CS166 Final project
CS166 Final projectCS166 Final project
CS166 Final project
 
Cs166 mynote
Cs166 mynoteCs166 mynote
Cs166 mynote
 
Cs166 hw1
Cs166 hw1Cs166 hw1
Cs166 hw1
 
Edited keeping happiness
Edited keeping happinessEdited keeping happiness
Edited keeping happiness
 
Database Management System Review
Database Management System ReviewDatabase Management System Review
Database Management System Review
 
Math178 hw7
Math178 hw7Math178 hw7
Math178 hw7
 
CS152 Programming Paradigm
CS152 Programming Paradigm CS152 Programming Paradigm
CS152 Programming Paradigm
 
Umap traversabilityin graph
Umap traversabilityin graphUmap traversabilityin graph
Umap traversabilityin graph
 
Price Distribution and Consumer Surplus
Price Distribution and Consumer Surplus Price Distribution and Consumer Surplus
Price Distribution and Consumer Surplus
 
Midterm review for CS156
Midterm review for CS156Midterm review for CS156
Midterm review for CS156
 
Jit complier
Jit complierJit complier
Jit complier
 
Methodologies of Software Engineering
Methodologies of Software EngineeringMethodologies of Software Engineering
Methodologies of Software Engineering
 

javascript

  • 1. JavaScript Presented by Team KAF San Jose State University Department of Computer Science CS152 Spring 2014 May 5th
  • 2. 1. Introduction to JavaScript 2. Object Oriented JavaScript 3. Data Types and Data Structures and Control Statements 4. Functions 5. Reference Agenda
  • 3. Introduction to Javascript • What is JavaScript • History • Cores • Today’s JavaScript • Features in Programming Paradigm
  • 4.  a dynamic computer language  (initially)Client side of programming language  First released in 1995 What is JavaScript?
  • 5.
  • 6.
  • 7.  Developed by Brendan Eich in Netscape communications  influenced by Shceme, self, Java, C, Python, AWK, HyperTalk  At 1996, Internet Explorer3.0 can run JavaScript  As the internet and web became popular, JavaScript become to play an important rule to enrich their website.  At 2005, Microsoft developed AJAX (JS and XML)  It becomes more popular language to develop web applications. History of JavaScript
  • 8.  ECMAScript: the scripting language standardized by Ecma International to reduce a compatible dialects of the language between Netscape and Microsoft.  Document Object Model (DOM) : provide supports for HTML and XML documents  Browser Object Model (BOM) : a set of objects related to the bowser environment primarily utilized in HTML5 3 cores of JavaScript
  • 9.  Create rich and powerful web applications  Write server-side code using .NET or Node.js As well as code that can run using Rhino(JS engine written in java )  Create Mobile Applications  Run on iPhone, Android and other phones  using PhoneGap or Titanium  Full-Stack for web application (UI-DB) by One Language  Especially MEAN stack Today’s JavaScript
  • 10. Features in Paradigm JavaScript  Script language  Prototype Based  Objected Oriented  Procedural  Functional  Dynamic Type Checking  Weakly Typed  On web browsers Java  Complied language  Class Based  Objected Oriented  Procedural  Static Type Checking  Strong Typed  On JVM
  • 11. Cont: Features in Paradigm JavaScript  Less Reliable  Weakly typed, unchecked parameters  Regularity  Generality  Orthogonal  Uniformity  Efficiency  Less: type checked at runtime  Extensibility  More: libraries and frameworks  Node.js, Angluer.js, Backbone.js.  Jquery , React….etc Java  More Reliable  Strong type, parameters checked  Regularity  Generality  Orthogonal  Uniformity  Efficiency  More: type checked by compiler  Extensibility  Less: libraries and frameworks
  • 13.  JavaScript is an object based language  Objects can store multiple properties.  Example var fruit = “apple”; var fruit = {type: “apple”, color: “red”, brand: “Fuji”} Objects
  • 14.  JavaScript is a prototype based objected oriented language  Which means that inheritance is performed by prototypes, rather than extending their functionalities in a place  Inheritance  Objects inherit from other objects since JavaScript does not have an idea of “class.”  When an object inherits from another object, it usually adds new methods to the inherited ones. Therefore, extending the old objects. Objected oriented JavaScript
  • 15. Example of inheritance JavaScript function Animal(name){ this.name = name; } Animal.prototype.speak = funciton(){ console.log(“my name is ” + this.name); }; var animal = new Animal(‘Monty’); animal.speak(); //My name is Monty function Cat(name){ Animal.call(this, name); } Cat.prototype = new Animal(); var cat = new Cat(‘Monty’); Cat.speak(); //My name is Monty java Public class Animal(){ Public Animal(name){ this.name = name; } }//Animal Public class Cat(name) extends Animal{ super(name); }//Cat Cat cat = new Cat(‘Monty’);
  • 16.  Primary difference between “class based” OO and “prototype based” OO is: Prototype based does not have classes. Prototypes
  • 17. Prototypes JavaScript function fruit(type, color, brand) { this.type = type; this.color = color; this.brand = brand; } var apple = new fruit(“apple”, “red”, “Fuji”); java public class Fruit(){ Fruit(str type, str color, str brand ) { this.type = type; this.color = color; this.brand = brand; } }//class Fruit apple = new Fruit(“apple”, “red”, “Fuji”); Treat “class” in java as a function in JS.
  • 18.  Encapsulation consists mainly of packing data into objects because there is no classes in JS.  prototyping is a common practice when enforcing encapsulation, as it allows for many object attributes and methods to be localized into a single object. Encapsulation
  • 19.  The capability to combine several objects into a new, more complex object is a functionality that JS supports.  An example: var fruit = {type: “apple”, color: “red”, brand: “Fuji”} Aggregation
  • 20. Data types and Data Structures and Control Statements
  • 21.  Number  String  Booleans  Array  Object  Undefined  Null Data Type TIPS! In JavaScript, undefined and Null are different. Null is an Object meaning it does not exists. While, undefined is value for a valuable without value. Number object supports Both double and int in java Primitive Types
  • 22.  Dynamically typed var y y = 8l x = 21 var newStr = “hello”;  Case Sensitive var randFruit = “apple”; var randfruit = “apple”; Variables They are two unique variables Declaring a variable without “var” notation will have global scope by default. With “var” notation, localize the scope of variable. Which implies, JS supports both global and local variables
  • 23.  Functions is not checked the number of parameters. function f(x, y) {// body } can call f(x,y) by all of the following: f(); f(1); f(3,true); Undefined Programmer’s response to make sure and pay attention to preconditions of function! All do not give you ERROR! Errors Caught by Compiler (checked) Errors Caught by Runtime (unchecked) Errors Caught by Nothing (Less Reliable) All Program Errors
  • 24.  To check the pre-condition, and to reveal errors as quickly as possible. You can use undefined! function f(x) { if(typeof x == “undefined”){ // not set! Missing parameter or something! x = 0; //make it default here! }//if else{//good to go the next!}//else } //f Undefined: check pre-condition
  • 25.  Supports major basic arithmetic operators{+,-,/,*}.  Also some syntactic sugars. var a = 123; var b = ++a; Result  a = 124, b = 124 var c = 123; var d = c--; Result  c =122, d = 123 Operators Same as Java!
  • 26. String Conversion  Number like string, js convers to a number automatically.  Can operate arithmetic on the string except addition.  Inverse operation is done by concatenating var n = “1”; n = n * 5 type of n; ----Inverse Operation------------ var n = 1; n = “” + n; type of n; String type String * numerical Number! Number type String + number String
  • 27.  Supports comparison symbols that java supports  Also, Operator symbol === to return true if both operands are equal AND the same type  Example 1 === “ 1”  false because of type 1 === 1  true 1 !== 1  false 1 !== ‘1’  true because of type Comparisons Equals == Not equals != Less < More > Less Equals <= More Equals >= Point: Equals == And equals value and type === are not the same!!!
  • 28.  Declaration of array:  Use [] surrounding your elements var arr = [1, “2”, 3, “4” ];  Access to the element arr[2] = “three” ; arr = [1, “2”, “three”, “4” ] ;  Add data: address an index where the outside of current boundary. var arr = [1,2,3]; arr[4] = “4th” arr = [1,2,3, undefined, “four”] Arrays Unlike java, can put any type in one array
  • 29.  Delete Elements: JS has delete operator. var arr = [1,2,3]; delete arr[1]; arr = [1, undefined, 3] Cont: Arrays But, it does not change its size…..
  • 30. Control Structures: if-statement Conventional var result = (a === 2) ? “a is two”: “a is not two”; Ordinary if(a === 2) { result = “a is two”; } else { result = “a is not two” ; } JavaScript also supports Switch-statement!
  • 31. Loops  4 types of loop  While loop  Do-while loop  For loop  For –in loop  For – in Loop var a = [‘a’, ‘b’, ‘c’]; var result = ‘n’; for(var i in a ) { result += “index” + i + “, value” + a[i]+ ‘n’; }
  • 33.  Declare function as below: function fucntionName() { //what to do } function functionName1(x){ //to do } function f(x, y ,z){ //do } Function
  • 34.  JavaScript passes values by Reference or by value  Primitive types, such as Numbers, String, Boolean are passed by Value  Changes in function not-directly affect to the original value.  Object and Array are passed by Reference  Changes in functions directly affect to the original value. Pass By…
  • 35. Function  Functional Programming Paradigm treat a function as the first class object.  Can assign function to variable.  Can pass function as parameters  Can return function function sum(x,y){ return a + b; } var newSum = sum; newSum (1,2); Result: 3 ---------------------------------------------------------------------
  • 37.  Json: stands for JS Object Notation.  a lightweight Data Interchange format.  Interchangeable between two different machine(big endian, little endian, etc)  Data Processing format.  use the format to store variables that is used in programs  Data Storage format: can store json into DB directly.  Self-contained format (able to adjust changes)  Data explain data itself.  JSON is used interchange and process and store.  Example actual products are Mongo DB, Open Data(Whether,,,etc) Json
  • 38. Json Many APIs are available to read/write/parse Json.
  • 40.  JavaScript (of course!)  jQuery: jQuery is a fast, small, and featured-rich JS library. It makes things like HTML doc traversal and manipulation, event handling, animation and Ajax much simpler with an easy to use API that works across a multitude of browsers.  Ajax: stands for asynchronous JS and XML.  With Ajax, web applications can send data to and retrieve from a server asynchronously(in the background) without interfering with the display and behavior of the existing page.  Json Demo Program Used
  • 41.  Object-Oriented JavaScript - Second Edition  By: Stoyan Stefanov; Kumar Chetan Sharma  Publisher: Packt Publishing  Pub. Date: July 26, 2013  JavaScript Programmer's Reference  By: Jonathan Reid; Thomas Valentine  Publisher: Apress  Pub. Date: June 05, 2013 Reference
  • 42.  Modern JavaScript Develop and Design  By: Larry Ullman  Publisher: Packt Publishing  Pub. Date: Feb 17, 2012 Reference

Editor's Notes

  1. Data format: Interchange format:Interchange between two different machine (big endian, little endian, etc) Processing format:use the format to store variables that is used in programs Storage format: can store json into DB directly. Not Self contained format: csv Xml 処理用には使わない。格納もしくは通信。 プログラムのなかで、xmlを書いて、メモリーから呼び出すことはしない。(プログラムの変数にいれる値として、使わない。) Jsonプログラムのなかで、jsonを読み書きしながらプログラムが動く。 Storage format: (mongo) can store json into DB directly.