SlideShare a Scribd company logo
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
github.com/nodeworkshop/setup
Setup your machine !
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
JavaScript Fundamentals
Deepank Vora
March/25/2015 NTU IEEE
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary.
Introduction
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 4
About the language
• Object-oriented dynamic language
• Frontend -> Backend
• World’s most misunderstood language
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 5
Differences from Java/C++
• No Classes. Object Prototypes
• Functions are first-class objects
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 6
Types
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 7
Types
• Number
• String
• Boolean
• Symbol
• Object
• Function
• Array
• Date
• RegExp
• null
• undefined
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 8
Number
• 64-bit floating point
• Be careful of floating point precision
Special Values
• NaN
• Infinity
• -Infinity
parseInt("123"); // 123
isNaN(parseInt("a")); // true
isFinite(1/0); // false
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 9
String
• Made up of Unicode characters
• Use string of length 1 to represent characters
Examples
"North Spine".length; // 11
"North Spine".charAt(0); // "N"
"North Spine".replace("North", "South"); // "South Spine"
"North Spine".toLowerCase(); // "north spine"
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 10
null and undefined
• null: Deliberate non-value
• var x = null;
console.log(x); // null
• undefined: uninitialized value
• var x;
console.log(x); // undefined
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 11
Boolean
• true or false
• Any value can be converted to a boolean
• false, 0, “”, NaN, null, undefined -> false
• Everything else -> true
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 12
Operators
• Arithmetic: +, -, *, /, %, ++, --
• Assignment: =, +=, -=, *=, /=, %=
• Logical: &&, ||, !
• Conditional: (condition) ? value1 : value2
• Comparison: ==, ===, !=, !==, >, <, >=, <=
• Bitwise
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 13
Control Structures
If-else
if (time < 10) {
greeting = "Good morning";
} else if (time < 20){
greeting = "Good day";
} else {
greeting = "Good evening";
}
Switch
switch(day){
case 0:
case 6:
text = "Weekend :)";
break;
default:
text = "Weekday :(";
break;
}
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 14
Control Structures
For
for(var i=0; i < 10; i++){
// executes 10 times
}
While and do-while
while(index<10){
index++;
}
var input;
do{
input = getInput();
} while (input != "0")
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 15
Lab 1.1
Write a program that uses console.log to print all the numbers from 1 to
100, with two exceptions. For numbers divisible by 3, print "Fizz" instead of
the number, and for numbers divisible by 5 (and not 3), print "Buzz" instead.
For numbers that are divisible by both 3 and 5, print "FizzBuzz".
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 16
Objects
• Simply a collection of name-value pairs
• Similar to Dictionaries in Python and HashMaps in Java
• Creating objects
var dog = { breed:"labrador", color:"brown" };
// OR
var dog = new Object();
dog.breed = "labrador";
dog.color = "brown";
• Get properties
dog.breed;
dog["breed"];
• Set properties
• dog.breed = "labrador";
dog["breed"] = "labrador";
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 17
Array
Creation
var a = new Array();
a[0] = "cat";
a[1] = "dog";
a.length; // 2
// OR
var a = ["cat", "dog"];
a[1]; //"dog"
a[10] = "mouse"
a[10]; // "mouse"
a[5]; //undefined
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 18
Function
function add(x, y) {
return x + y;
}
add(1, 2); // ?
add(); // ?
add(1, 2, 5); // ?
function add() {
var sum = 0;
for (var i = 0, j = arguments.length; i < j; i++) {
sum += arguments[i];
}
return sum;
}
add(1,2,3,4); // ?
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 19
Lab 1.2
Write a range function that takes two arguments, start and end, and returns
an array containing all the numbers from start up to (and including) end.
Next, write a sum function that takes an array of numbers and returns the
sum of these numbers. Print sum(range(1,10)) and see whether it does
indeed return 55.
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 20
Custom Objects
function Person(first, last) {
this.first = first;
this.last = last;
this.fullName = function() {
return this.first + ' ' + this.last;
};
}
var p = new Person("Barack", "Obama");
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 21
Lab 1.3
Write a constructor Vector that represents a vector in two-dimensional
space. It takes x and y parameters (numbers), which it should save to
properties of the same name.
Give Vector two methods, plus and minus, that take another vector as a
parameter and return a new vector that has the sum or difference of the two
vectors’ (the one in this and the parameter) x and y values.
Add a method length which computes the length of the vector—that is, the
distance of the point (x, y) from the origin (0, 0).
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 22
Callback functions
• A callback is a function reference
• Often defined in-line where it's required
• Typically used for "one-off" asynchronous invocations
Calls function
after 1 sec
setTimeout(function() {
console.log(new Date())
}, 1000);
Inline
callback
Anonymous
© 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 23
Lab 1.4
Define a function add that takes in two numbers as parameters and a third
callback parameter. This function should call the callback function, passing
the result of addition to the callback function as an argument.
Call add, passing two numbers and a callback (defined in-line). The
callback should print “The sum is: __”

More Related Content

What's hot

JavaScript for ABAP Programmers - 5/7 Functions
JavaScript for ABAP Programmers - 5/7 FunctionsJavaScript for ABAP Programmers - 5/7 Functions
JavaScript for ABAP Programmers - 5/7 Functions
Chris Whealy
 
RIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWTRIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWT
Michael Galpin
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
Daniel Spector
 
Jakarta EE Recipes
Jakarta EE RecipesJakarta EE Recipes
Jakarta EE Recipes
Josh Juneau
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
Christian Melchior
 
Wcf data services
Wcf data servicesWcf data services
Wcf data services
Eyal Vardi
 
How Pony ORM translates Python generators to SQL queries
How Pony ORM translates Python generators to SQL queriesHow Pony ORM translates Python generators to SQL queries
How Pony ORM translates Python generators to SQL queries
ponyorm
 
Introduction to React Native Workshop
Introduction to React Native WorkshopIntroduction to React Native Workshop
Introduction to React Native Workshop
Ignacio Martín
 
Julio Capote, Twitter
Julio Capote, TwitterJulio Capote, Twitter
Julio Capote, Twitter
Ontico
 
Reactive Applications in Enterprise Java
Reactive Applications in Enterprise JavaReactive Applications in Enterprise Java
Reactive Applications in Enterprise Java
OPEN KNOWLEDGE GmbH
 
Scala Presentation Work
Scala Presentation WorkScala Presentation Work
Scala Presentation WorkSkills Matter
 
(DAT401) Amazon DynamoDB Deep Dive
(DAT401) Amazon DynamoDB Deep Dive(DAT401) Amazon DynamoDB Deep Dive
(DAT401) Amazon DynamoDB Deep Dive
Amazon Web Services
 
Firebase ng2 zurich
Firebase ng2 zurichFirebase ng2 zurich
Firebase ng2 zurich
Christoffer Noring
 
React Native Workshop - React Alicante
React Native Workshop - React AlicanteReact Native Workshop - React Alicante
React Native Workshop - React Alicante
Ignacio Martín
 
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
Amazon Web Services
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklum Ukraine
 
Journey's end
Journey's endJourney's end
Journey's end
Maurice Naftalin
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
Patrycja Wegrzynowicz
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
Vincent Pradeilles
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
Konrad Malawski
 

What's hot (20)

JavaScript for ABAP Programmers - 5/7 Functions
JavaScript for ABAP Programmers - 5/7 FunctionsJavaScript for ABAP Programmers - 5/7 Functions
JavaScript for ABAP Programmers - 5/7 Functions
 
RIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWTRIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWT
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
Jakarta EE Recipes
Jakarta EE RecipesJakarta EE Recipes
Jakarta EE Recipes
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
 
Wcf data services
Wcf data servicesWcf data services
Wcf data services
 
How Pony ORM translates Python generators to SQL queries
How Pony ORM translates Python generators to SQL queriesHow Pony ORM translates Python generators to SQL queries
How Pony ORM translates Python generators to SQL queries
 
Introduction to React Native Workshop
Introduction to React Native WorkshopIntroduction to React Native Workshop
Introduction to React Native Workshop
 
Julio Capote, Twitter
Julio Capote, TwitterJulio Capote, Twitter
Julio Capote, Twitter
 
Reactive Applications in Enterprise Java
Reactive Applications in Enterprise JavaReactive Applications in Enterprise Java
Reactive Applications in Enterprise Java
 
Scala Presentation Work
Scala Presentation WorkScala Presentation Work
Scala Presentation Work
 
(DAT401) Amazon DynamoDB Deep Dive
(DAT401) Amazon DynamoDB Deep Dive(DAT401) Amazon DynamoDB Deep Dive
(DAT401) Amazon DynamoDB Deep Dive
 
Firebase ng2 zurich
Firebase ng2 zurichFirebase ng2 zurich
Firebase ng2 zurich
 
React Native Workshop - React Alicante
React Native Workshop - React AlicanteReact Native Workshop - React Alicante
React Native Workshop - React Alicante
 
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
 
Journey's end
Journey's endJourney's end
Journey's end
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
An introduction to property-based testing
An introduction to property-based testingAn introduction to property-based testing
An introduction to property-based testing
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
 

Viewers also liked

Actitudes en un despacho
Actitudes en un despachoActitudes en un despacho
Actitudes en un despacho
salolu1977
 
Oasis Hi-Tech Sportswear Ltd. Social Responsibility
Oasis Hi-Tech Sportswear Ltd. Social ResponsibilityOasis Hi-Tech Sportswear Ltd. Social Responsibility
Oasis Hi-Tech Sportswear Ltd. Social ResponsibilityZabed Wali
 
How to Increase Audience Engagement at Events
How to Increase Audience Engagement at EventsHow to Increase Audience Engagement at Events
How to Increase Audience Engagement at Events
event2mobile
 
How ready is your organization for change?
How ready is your organization for change?How ready is your organization for change?
How ready is your organization for change?
Linkageinc
 
How RGB Broadcasting Competes with Other Brand Players in Over the Top (OTT) ...
How RGB Broadcasting Competes with Other Brand Players in Over the Top (OTT) ...How RGB Broadcasting Competes with Other Brand Players in Over the Top (OTT) ...
How RGB Broadcasting Competes with Other Brand Players in Over the Top (OTT) ...
Alvin Thomas
 
Lwm content marketing event public
Lwm content marketing event   publicLwm content marketing event   public
Lwm content marketing event publicnatashasudan
 
Give More Value to Your Association Members and Sponsors
Give More Value to Your Association Members and SponsorsGive More Value to Your Association Members and Sponsors
Give More Value to Your Association Members and Sponsors
event2mobile
 
Engl102 assignment3final
Engl102 assignment3finalEngl102 assignment3final
Engl102 assignment3final
John Le
 
Vincent Walsh MSc by Research Thesis Sept 2014 (1)
Vincent Walsh MSc by Research Thesis Sept 2014 (1)Vincent Walsh MSc by Research Thesis Sept 2014 (1)
Vincent Walsh MSc by Research Thesis Sept 2014 (1)Vincent Walsh
 
Interaksi 7.1 ulasan jurnal
Interaksi 7.1 ulasan jurnalInteraksi 7.1 ulasan jurnal
Interaksi 7.1 ulasan jurnal
rohayuibrahim
 
Javascript - SST
Javascript - SSTJavascript - SST
Javascript - SST
Deepank Vora
 
Season and Career Totals, Records, and Rankings for 2014-2015 Season
Season and Career Totals, Records, and Rankings for 2014-2015 SeasonSeason and Career Totals, Records, and Rankings for 2014-2015 Season
Season and Career Totals, Records, and Rankings for 2014-2015 SeasonTim Ross
 

Viewers also liked (14)

Actitudes en un despacho
Actitudes en un despachoActitudes en un despacho
Actitudes en un despacho
 
Oasis Hi-Tech Sportswear Ltd. Social Responsibility
Oasis Hi-Tech Sportswear Ltd. Social ResponsibilityOasis Hi-Tech Sportswear Ltd. Social Responsibility
Oasis Hi-Tech Sportswear Ltd. Social Responsibility
 
How to Increase Audience Engagement at Events
How to Increase Audience Engagement at EventsHow to Increase Audience Engagement at Events
How to Increase Audience Engagement at Events
 
How ready is your organization for change?
How ready is your organization for change?How ready is your organization for change?
How ready is your organization for change?
 
How RGB Broadcasting Competes with Other Brand Players in Over the Top (OTT) ...
How RGB Broadcasting Competes with Other Brand Players in Over the Top (OTT) ...How RGB Broadcasting Competes with Other Brand Players in Over the Top (OTT) ...
How RGB Broadcasting Competes with Other Brand Players in Over the Top (OTT) ...
 
Lwm content marketing event public
Lwm content marketing event   publicLwm content marketing event   public
Lwm content marketing event public
 
anakage_skilling
anakage_skillinganakage_skilling
anakage_skilling
 
Dapatan kajian
Dapatan kajianDapatan kajian
Dapatan kajian
 
Give More Value to Your Association Members and Sponsors
Give More Value to Your Association Members and SponsorsGive More Value to Your Association Members and Sponsors
Give More Value to Your Association Members and Sponsors
 
Engl102 assignment3final
Engl102 assignment3finalEngl102 assignment3final
Engl102 assignment3final
 
Vincent Walsh MSc by Research Thesis Sept 2014 (1)
Vincent Walsh MSc by Research Thesis Sept 2014 (1)Vincent Walsh MSc by Research Thesis Sept 2014 (1)
Vincent Walsh MSc by Research Thesis Sept 2014 (1)
 
Interaksi 7.1 ulasan jurnal
Interaksi 7.1 ulasan jurnalInteraksi 7.1 ulasan jurnal
Interaksi 7.1 ulasan jurnal
 
Javascript - SST
Javascript - SSTJavascript - SST
Javascript - SST
 
Season and Career Totals, Records, and Rankings for 2014-2015 Season
Season and Career Totals, Records, and Rankings for 2014-2015 SeasonSeason and Career Totals, Records, and Rankings for 2014-2015 Season
Season and Career Totals, Records, and Rankings for 2014-2015 Season
 

Similar to JavaScript Fundamentals

Javascript - ITE
Javascript - ITEJavascript - ITE
Javascript - ITE
Deepank Vora
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdf
katarichallenge
 
Node.js Workshop
Node.js WorkshopNode.js Workshop
Node.js Workshop
Quhan Arunasalam
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal Architecture
Jeroen Rosenberg
 
Nalinee java
Nalinee javaNalinee java
Nalinee java
Nalinee Choudhary
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
Pascal Rettig
 
First impression of the new cloud native programming language ballerina
First impression of the new cloud native programming language ballerinaFirst impression of the new cloud native programming language ballerina
First impression of the new cloud native programming language ballerina
Richárd Kovács
 
Node.js primer
Node.js primerNode.js primer
Node.js primer
Quhan Arunasalam
 
Drupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the islandDrupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the island
Angela Byron
 
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten ZiegelerOSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
mfrancis
 
Toronto MuleSoft Meetup: Virtual Meetup #2
Toronto MuleSoft Meetup: Virtual Meetup #2Toronto MuleSoft Meetup: Virtual Meetup #2
Toronto MuleSoft Meetup: Virtual Meetup #2
Alexandra N. Martinez
 
Liberated APIs in ClojureLand - Paris Clojure User Group
Liberated APIs in ClojureLand - Paris Clojure User GroupLiberated APIs in ClojureLand - Paris Clojure User Group
Liberated APIs in ClojureLand - Paris Clojure User Group
Gaylord Mazelier
 
Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4
ICS
 
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NYPuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
Puppet
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
gturnquist
 
Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0
Subhash Patel
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
Akash Pandey
 
Tests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and TestacularTests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and Testacular
Paulo Cesar Ortins Brito
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
Eric Phan
 
Reactive Extensions .NET
Reactive Extensions .NETReactive Extensions .NET
Reactive Extensions .NET
George Taskos
 

Similar to JavaScript Fundamentals (20)

Javascript - ITE
Javascript - ITEJavascript - ITE
Javascript - ITE
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdf
 
Node.js Workshop
Node.js WorkshopNode.js Workshop
Node.js Workshop
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal Architecture
 
Nalinee java
Nalinee javaNalinee java
Nalinee java
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
First impression of the new cloud native programming language ballerina
First impression of the new cloud native programming language ballerinaFirst impression of the new cloud native programming language ballerina
First impression of the new cloud native programming language ballerina
 
Node.js primer
Node.js primerNode.js primer
Node.js primer
 
Drupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the islandDrupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the island
 
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten ZiegelerOSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
 
Toronto MuleSoft Meetup: Virtual Meetup #2
Toronto MuleSoft Meetup: Virtual Meetup #2Toronto MuleSoft Meetup: Virtual Meetup #2
Toronto MuleSoft Meetup: Virtual Meetup #2
 
Liberated APIs in ClojureLand - Paris Clojure User Group
Liberated APIs in ClojureLand - Paris Clojure User GroupLiberated APIs in ClojureLand - Paris Clojure User Group
Liberated APIs in ClojureLand - Paris Clojure User Group
 
Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4
 
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NYPuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Tests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and TestacularTests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and Testacular
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
 
Reactive Extensions .NET
Reactive Extensions .NETReactive Extensions .NET
Reactive Extensions .NET
 

Recently uploaded

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 

Recently uploaded (20)

AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 

JavaScript Fundamentals

  • 1. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. github.com/nodeworkshop/setup Setup your machine !
  • 2. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. JavaScript Fundamentals Deepank Vora March/25/2015 NTU IEEE
  • 3. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. Introduction
  • 4. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 4 About the language • Object-oriented dynamic language • Frontend -> Backend • World’s most misunderstood language
  • 5. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 5 Differences from Java/C++ • No Classes. Object Prototypes • Functions are first-class objects
  • 6. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 6 Types
  • 7. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 7 Types • Number • String • Boolean • Symbol • Object • Function • Array • Date • RegExp • null • undefined
  • 8. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 8 Number • 64-bit floating point • Be careful of floating point precision Special Values • NaN • Infinity • -Infinity parseInt("123"); // 123 isNaN(parseInt("a")); // true isFinite(1/0); // false
  • 9. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 9 String • Made up of Unicode characters • Use string of length 1 to represent characters Examples "North Spine".length; // 11 "North Spine".charAt(0); // "N" "North Spine".replace("North", "South"); // "South Spine" "North Spine".toLowerCase(); // "north spine"
  • 10. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 10 null and undefined • null: Deliberate non-value • var x = null; console.log(x); // null • undefined: uninitialized value • var x; console.log(x); // undefined
  • 11. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 11 Boolean • true or false • Any value can be converted to a boolean • false, 0, “”, NaN, null, undefined -> false • Everything else -> true
  • 12. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 12 Operators • Arithmetic: +, -, *, /, %, ++, -- • Assignment: =, +=, -=, *=, /=, %= • Logical: &&, ||, ! • Conditional: (condition) ? value1 : value2 • Comparison: ==, ===, !=, !==, >, <, >=, <= • Bitwise
  • 13. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 13 Control Structures If-else if (time < 10) { greeting = "Good morning"; } else if (time < 20){ greeting = "Good day"; } else { greeting = "Good evening"; } Switch switch(day){ case 0: case 6: text = "Weekend :)"; break; default: text = "Weekday :("; break; }
  • 14. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 14 Control Structures For for(var i=0; i < 10; i++){ // executes 10 times } While and do-while while(index<10){ index++; } var input; do{ input = getInput(); } while (input != "0")
  • 15. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 15 Lab 1.1 Write a program that uses console.log to print all the numbers from 1 to 100, with two exceptions. For numbers divisible by 3, print "Fizz" instead of the number, and for numbers divisible by 5 (and not 3), print "Buzz" instead. For numbers that are divisible by both 3 and 5, print "FizzBuzz".
  • 16. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 16 Objects • Simply a collection of name-value pairs • Similar to Dictionaries in Python and HashMaps in Java • Creating objects var dog = { breed:"labrador", color:"brown" }; // OR var dog = new Object(); dog.breed = "labrador"; dog.color = "brown"; • Get properties dog.breed; dog["breed"]; • Set properties • dog.breed = "labrador"; dog["breed"] = "labrador";
  • 17. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 17 Array Creation var a = new Array(); a[0] = "cat"; a[1] = "dog"; a.length; // 2 // OR var a = ["cat", "dog"]; a[1]; //"dog" a[10] = "mouse" a[10]; // "mouse" a[5]; //undefined
  • 18. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 18 Function function add(x, y) { return x + y; } add(1, 2); // ? add(); // ? add(1, 2, 5); // ? function add() { var sum = 0; for (var i = 0, j = arguments.length; i < j; i++) { sum += arguments[i]; } return sum; } add(1,2,3,4); // ?
  • 19. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 19 Lab 1.2 Write a range function that takes two arguments, start and end, and returns an array containing all the numbers from start up to (and including) end. Next, write a sum function that takes an array of numbers and returns the sum of these numbers. Print sum(range(1,10)) and see whether it does indeed return 55.
  • 20. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 20 Custom Objects function Person(first, last) { this.first = first; this.last = last; this.fullName = function() { return this.first + ' ' + this.last; }; } var p = new Person("Barack", "Obama");
  • 21. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 21 Lab 1.3 Write a constructor Vector that represents a vector in two-dimensional space. It takes x and y parameters (numbers), which it should save to properties of the same name. Give Vector two methods, plus and minus, that take another vector as a parameter and return a new vector that has the sum or difference of the two vectors’ (the one in this and the parameter) x and y values. Add a method length which computes the length of the vector—that is, the distance of the point (x, y) from the origin (0, 0).
  • 22. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 22 Callback functions • A callback is a function reference • Often defined in-line where it's required • Typically used for "one-off" asynchronous invocations Calls function after 1 sec setTimeout(function() { console.log(new Date()) }, 1000); Inline callback Anonymous
  • 23. © 2015 PayPal Inc. All rights reserved. Confidential and proprietary. 23 Lab 1.4 Define a function add that takes in two numbers as parameters and a third callback parameter. This function should call the callback function, passing the result of addition to the callback function as an argument. Call add, passing two numbers and a callback (defined in-line). The callback should print “The sum is: __”

Editor's Notes

  1. Difference between == and === String concatenation with +
  2. return; returns undefined, not null. No return: returns undefined
  3. New – 1. Creates empty object. 2. Calls Person function with ‘this’ set to the new object. 3. Returns the new object.