SlideShare ist ein Scribd-Unternehmen logo
1 von 70
Downloaden Sie, um offline zu lesen
Introduction to
JavaScript #1
@danielknell
Basics
Basics
‱Expressions
‱Conditionals
‱Loops
Expressions
Expressions
‱Math and Numbers
‱Strings and Concatenation
‱Special
‱Booleans and Comparison
‱Functions
‱Objects and Arrays
http://artsn.co/js-repl
Numbers and Math
42
42.5
× Ă· + −
Math
4 * 2;
4 / 2;
4 + 2;
4 - 2;
100 % 3;
99 + (9 / 9);
-3;
-(3+1);
Mathmagical
Take a 4 digit
number
e.g. 1234
ShufïŹ‚e the digits
e.g. 2413
Subtract the smaller
from the larger
e.g. 2413 - 1234
Sum the digits of the
result
e.g. 566 → 5 + 6 + 6 → 1 + 7 → 8
Sum the digits of the
result
e.g. 566 % 8
0
Variables
Variables
var x = 5;
var y = 99 + (9 / 9);
var z = x * y;
More Math
var x = 5;
x++;
x--;
Strings and
Concatenation
Strings
"hello";
'world';
"hello" + "world";
Strings
"five plus two equals: " + (5 + 2);
Strings
var who = 'world';
var greeting = "hello" + who;
greeting[0]
Special
null
null
var x = null;
undeïŹned
undeïŹned
var x;
Boolean and
Comparison
True / False
False-ish
0
""
null
undefined
Boolean Math
true && true;
false || true;
!false;
Comparison
1 == "1";
1 != "2";
2 > "1";
1 < "2";
2 >= "1";
1 <= "2";
1 === 1;
1 !== "1";
Functions
Functions
function greet(who) {
return "hello" + who;
}
greet("world");
Functions
var greet = function(who) {
return "hello" + who;
}
greet("world");
Arrays and Objects
Arrays
var a = [1, 2, "three"];
a[0]; // 1
a[2]; // "three"
a.length; // 3
a[3]; // undefiend
Arrays
var a = [1, 2, "three"];
a.push("four");
a; // [1, 2, "three", "four"]
var last = a.pop();
a; [1, 2, "three"]
last; // "four"
var first = a.shift();
a; [2, "three"]
first; // 1
a.unshift("one");
a; ["one", 2, "three"]
Objects
var coords = { x: 1, "y": 2 };
coords["x"]; // 1
coords.y; // 2
coords.z; // undefined
{ var: 1 }
{ "var": 1 }
Conditionals
Conditionals
http://www.ïŹ‚ickr.com/photos/blahïŹ‚owers/4765476166
Conditionals
Conditionals
if the light is green
cross the road
else
stop
Conditionals
if (light === 'green') {
crossTheRoad();
}
else {
stop();
}
Conditionals
switch (light) {
case 'blue':
case 'green':
crossTheRoad();
break;
case 'red':
stop();
break;
default:
lookConfused();
}
Loops
Loops
http://www.ïŹ‚ickr.com/photos/blahïŹ‚owers/4765476166
Loops
Loops
while light is red
wait
cross the road
Loops
while (light === 'red') {
wait();
}
crossTheRoad();
Loops
do {
wait();
} while (light === 'red');
crossTheRoad();
Loops
for (var i = 0; i < 8; i++) {
potato(i);
}
more();
Loops
while (light === 'red') {
if (axeMurder === true) {
break;
}
wait();
}
crossTheRoad();
Loops
do {
wait();
if (light === 'flashing green') {
continue;
}
} while (light === 'red');
crossTheRoad();
Combined
Combined
http://www.ïŹ‚ickr.com/photos/davelevy/7190079438
Combined
Combined
while light is not green
if light is red
wait
if light is amber
get ready
GO GO GO!
Combined
while (light != 'green') {
switch (light) {
case "red":
wait();
break;
case "amber":
getReady();
break;
default:
lookConfused();
}
}
goGoGo();
Complex Objects
Complex Objects
var person = {
name: "bob"
, greet: function() {
return "hi " + this.name + "!";
}
}
person.greet();
Complex Objects
var person = {
name: "bob"
, greet: function() {
return "hi " + this.name + "!";
}
}
console.log(person.greet());
Fizz Buzz
Fizz Buzz
‱Count to 100 printing each number
‱For numbers divisible by 3 print “Fizz”
instead
‱For numbers divisible by 5 print “Buzz”
instead
‱For numbers divisible by 3 and 5 print
“FizzBuzz” instead
Fizz Buzz
Fizz Buzz
‱Count to 100 printing
each number
‱For numbers divisible by
3 print “Fizz” instead
‱For numbers divisible by
5 print “Buzz” instead
‱For numbers divisible by
3 and 5 print
“FizzBuzz” instead
Thats All Folks
email: contact@danielknell.co.uk
twitter: @danielknell
website: http://danielknell.co.uk/

Weitere Àhnliche Inhalte

Andere mochten auch

An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5
Event Handler
 
The big bang theory - UNIT 2
The big bang theory - UNIT 2The big bang theory - UNIT 2
The big bang theory - UNIT 2
lm092068
 
Introduction to JavaScript: Week Two
Introduction to JavaScript: Week TwoIntroduction to JavaScript: Week Two
Introduction to JavaScript: Week Two
Event Handler
 
An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week 3An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week 3
Event Handler
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup EmpireThe Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
Seh Hui Leong
 
An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4
Event Handler
 
Big Bang Theorychandler
Big Bang TheorychandlerBig Bang Theorychandler
Big Bang Theorychandler
guest008d7bd
 

Andere mochten auch (20)

Java Script
Java ScriptJava Script
Java Script
 
An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5
 
The big bang theory of social recruiting
The big bang theory of social recruitingThe big bang theory of social recruiting
The big bang theory of social recruiting
 
The big bang theory - UNIT 2
The big bang theory - UNIT 2The big bang theory - UNIT 2
The big bang theory - UNIT 2
 
Introduction to JavaScript: Week Two
Introduction to JavaScript: Week TwoIntroduction to JavaScript: Week Two
Introduction to JavaScript: Week Two
 
8. java script
8. java script8. java script
8. java script
 
An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week 3An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week 3
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup EmpireThe Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
Unchallengeable miracle of Holy Quran
Unchallengeable miracle of  Holy QuranUnchallengeable miracle of  Holy Quran
Unchallengeable miracle of Holy Quran
 
An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
 
Big Bang Theory
Big Bang TheoryBig Bang Theory
Big Bang Theory
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
 
Chapter 1 - How the world begin
Chapter 1 - How the world beginChapter 1 - How the world begin
Chapter 1 - How the world begin
 
Big Bang Theorychandler
Big Bang TheorychandlerBig Bang Theorychandler
Big Bang Theorychandler
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript Development
 
Qur’an and its sciences
Qur’an and its sciencesQur’an and its sciences
Qur’an and its sciences
 
The Quran and Computational Linguistics
The Quran and Computational LinguisticsThe Quran and Computational Linguistics
The Quran and Computational Linguistics
 
Java script Learn Easy
Java script Learn Easy Java script Learn Easy
Java script Learn Easy
 

Ähnlich wie An Introduction to JavaScript: Week One

4 1 radicals and pythagorean theorem
4 1 radicals and pythagorean theorem4 1 radicals and pythagorean theorem
4 1 radicals and pythagorean theorem
math123b
 
LinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroLinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: Intro
Adam Crabtree
 

Ähnlich wie An Introduction to JavaScript: Week One (20)

4 1 radicals and pythagorean theorem-x
4 1 radicals and pythagorean theorem-x4 1 radicals and pythagorean theorem-x
4 1 radicals and pythagorean theorem-x
 
4 1 radicals and pythagorean theorem
4 1 radicals and pythagorean theorem4 1 radicals and pythagorean theorem
4 1 radicals and pythagorean theorem
 
3 square roots and 2nd degree equations nat-e
3 square roots and 2nd degree equations  nat-e3 square roots and 2nd degree equations  nat-e
3 square roots and 2nd degree equations nat-e
 
Statistical Schema Induction
Statistical Schema InductionStatistical Schema Induction
Statistical Schema Induction
 
Introduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScriptIntroduction to Functional Programming with Haskell and JavaScript
Introduction to Functional Programming with Haskell and JavaScript
 
Parsing with Perl6 Grammars
Parsing with Perl6 GrammarsParsing with Perl6 Grammars
Parsing with Perl6 Grammars
 
JavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuanJavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuan
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
Java micro optimizations 2017
Java micro optimizations 2017Java micro optimizations 2017
Java micro optimizations 2017
 
Data Wars: The Bloody Enterprise strikes back
Data Wars: The Bloody Enterprise strikes backData Wars: The Bloody Enterprise strikes back
Data Wars: The Bloody Enterprise strikes back
 
4 radicals and pythagorean theorem x
4 radicals and pythagorean theorem x4 radicals and pythagorean theorem x
4 radicals and pythagorean theorem x
 
Julia: The language for future
Julia: The language for futureJulia: The language for future
Julia: The language for future
 
2.2 Circles
2.2 Circles2.2 Circles
2.2 Circles
 
LinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: IntroLinkedIn TBC JavaScript 100: Intro
LinkedIn TBC JavaScript 100: Intro
 
Basic algebra and graphing
Basic algebra and graphing Basic algebra and graphing
Basic algebra and graphing
 
Algebra Trigonometry Problems
Algebra Trigonometry ProblemsAlgebra Trigonometry Problems
Algebra Trigonometry Problems
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Short notes on mathematics
Short notes on mathematicsShort notes on mathematics
Short notes on mathematics
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
tetris
tetristetris
tetris
 

Mehr von Event Handler (8)

Selling UCD: Getting buy-in and measuring the value of UX
Selling UCD: Getting buy-in and measuring the value of UXSelling UCD: Getting buy-in and measuring the value of UX
Selling UCD: Getting buy-in and measuring the value of UX
 
Best Practice for UX Deliverables - 2014
Best Practice for UX Deliverables - 2014Best Practice for UX Deliverables - 2014
Best Practice for UX Deliverables - 2014
 
From Chuck D to Chuck D: Evolution, Synthetic Biology and the History of Hip Hop
From Chuck D to Chuck D: Evolution, Synthetic Biology and the History of Hip HopFrom Chuck D to Chuck D: Evolution, Synthetic Biology and the History of Hip Hop
From Chuck D to Chuck D: Evolution, Synthetic Biology and the History of Hip Hop
 
Tumours and Tree Trunks - GeekyScience: Evolution
Tumours and Tree Trunks - GeekyScience: EvolutionTumours and Tree Trunks - GeekyScience: Evolution
Tumours and Tree Trunks - GeekyScience: Evolution
 
Best Practice for UX Deliverables
Best Practice for UX DeliverablesBest Practice for UX Deliverables
Best Practice for UX Deliverables
 
The Missing Ingredient
The Missing IngredientThe Missing Ingredient
The Missing Ingredient
 
Productivity quickly
Productivity quicklyProductivity quickly
Productivity quickly
 
Anna pickard geekyfinal
Anna pickard geekyfinalAnna pickard geekyfinal
Anna pickard geekyfinal
 

KĂŒrzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

KĂŒrzlich hochgeladen (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
 

An Introduction to JavaScript: Week One