SlideShare a Scribd company logo
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
Shuffle 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;
undefined
undefined
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.flickr.com/photos/blahflowers/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.flickr.com/photos/blahflowers/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.flickr.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/

More Related Content

Viewers also liked (20)

PPT
Java Script
siddaram
 
PDF
An Introduction to JavaScript: Week 5
Event Handler
 
PPTX
The big bang theory of social recruiting
FastCollab
 
PPTX
The big bang theory - UNIT 2
lm092068
 
PDF
Introduction to JavaScript: Week Two
Event Handler
 
PPTX
8. java script
AnusAhmad
 
PDF
An Introduction to JavaScript: Week 3
Event Handler
 
PDF
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
Seh Hui Leong
 
PPT
JAVA SCRIPT
Go4Guru
 
PDF
Unchallengeable miracle of Holy Quran
yoursincerefriend
 
PDF
An Introduction to JavaScript: Week 4
Event Handler
 
PPTX
Introduction to Java Script
Vijay Kumar Verma
 
PPTX
Big Bang Theory
Kevin James
 
PPT
Java script -23jan2015
Sasidhar Kothuru
 
PPT
Chapter 1 - How the world begin
Green Pond Baptist Church
 
PPTX
Big Bang Theorychandler
guest008d7bd
 
PDF
Large-Scale JavaScript Development
Addy Osmani
 
PPTX
Qur’an and its sciences
Kalsoom Mohammed
 
PPT
The Quran and Computational Linguistics
Abdul Baquee Muhammad Sharaf
 
PPT
Java script Learn Easy
prince Loffar
 
Java Script
siddaram
 
An Introduction to JavaScript: Week 5
Event Handler
 
The big bang theory of social recruiting
FastCollab
 
The big bang theory - UNIT 2
lm092068
 
Introduction to JavaScript: Week Two
Event Handler
 
8. java script
AnusAhmad
 
An Introduction to JavaScript: Week 3
Event Handler
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
Seh Hui Leong
 
JAVA SCRIPT
Go4Guru
 
Unchallengeable miracle of Holy Quran
yoursincerefriend
 
An Introduction to JavaScript: Week 4
Event Handler
 
Introduction to Java Script
Vijay Kumar Verma
 
Big Bang Theory
Kevin James
 
Java script -23jan2015
Sasidhar Kothuru
 
Chapter 1 - How the world begin
Green Pond Baptist Church
 
Big Bang Theorychandler
guest008d7bd
 
Large-Scale JavaScript Development
Addy Osmani
 
Qur’an and its sciences
Kalsoom Mohammed
 
The Quran and Computational Linguistics
Abdul Baquee Muhammad Sharaf
 
Java script Learn Easy
prince Loffar
 

Similar to An Introduction to JavaScript: Week One (20)

PPTX
4 1 radicals and pythagorean theorem-x
math123b
 
PPTX
4 1 radicals and pythagorean theorem
math123b
 
PPTX
3 square roots and 2nd degree equations nat-e
math260
 
PDF
Statistical Schema Induction
Johanna Voelker
 
PDF
Introduction to Functional Programming with Haskell and JavaScript
Will Kurt
 
ODP
Parsing with Perl6 Grammars
abrummett
 
PDF
JavaScript Beginner Tutorial | WeiYuan
Wei-Yuan Chang
 
PPT
Ruby on Rails Intro
zhang tao
 
PDF
Java micro optimizations 2017
Dmitriy Dumanskiy
 
PPTX
Data Wars: The Bloody Enterprise strikes back
Victor_Cr
 
PPTX
4 radicals and pythagorean theorem x
Tzenma
 
PDF
Julia: The language for future
岳華 杜
 
PDF
2.2 Circles
smiller5
 
PPTX
LinkedIn TBC JavaScript 100: Intro
Adam Crabtree
 
PDF
Basic algebra and graphing
Bob Marcus
 
PDF
Algebra Trigonometry Problems
Don Dooley
 
PPTX
Fact, Fiction, and FP
Brian Lonsdorf
 
PDF
Short notes on mathematics
Directorate of Education Delhi
 
PDF
How to write code you won't hate tomorrow
Pete McFarlane
 
DOCX
tetris
Cameron White
 
4 1 radicals and pythagorean theorem-x
math123b
 
4 1 radicals and pythagorean theorem
math123b
 
3 square roots and 2nd degree equations nat-e
math260
 
Statistical Schema Induction
Johanna Voelker
 
Introduction to Functional Programming with Haskell and JavaScript
Will Kurt
 
Parsing with Perl6 Grammars
abrummett
 
JavaScript Beginner Tutorial | WeiYuan
Wei-Yuan Chang
 
Ruby on Rails Intro
zhang tao
 
Java micro optimizations 2017
Dmitriy Dumanskiy
 
Data Wars: The Bloody Enterprise strikes back
Victor_Cr
 
4 radicals and pythagorean theorem x
Tzenma
 
Julia: The language for future
岳華 杜
 
2.2 Circles
smiller5
 
LinkedIn TBC JavaScript 100: Intro
Adam Crabtree
 
Basic algebra and graphing
Bob Marcus
 
Algebra Trigonometry Problems
Don Dooley
 
Fact, Fiction, and FP
Brian Lonsdorf
 
Short notes on mathematics
Directorate of Education Delhi
 
How to write code you won't hate tomorrow
Pete McFarlane
 
Ad

More from Event Handler (8)

PDF
Selling UCD: Getting buy-in and measuring the value of UX
Event Handler
 
PDF
Best Practice for UX Deliverables - 2014
Event Handler
 
PPT
From Chuck D to Chuck D: Evolution, Synthetic Biology and the History of Hip Hop
Event Handler
 
PPTX
Tumours and Tree Trunks - GeekyScience: Evolution
Event Handler
 
PDF
Best Practice for UX Deliverables
Event Handler
 
PPSX
The Missing Ingredient
Event Handler
 
PPTX
Productivity quickly
Event Handler
 
PPTX
Anna pickard geekyfinal
Event Handler
 
Selling UCD: Getting buy-in and measuring the value of UX
Event Handler
 
Best Practice for UX Deliverables - 2014
Event Handler
 
From Chuck D to Chuck D: Evolution, Synthetic Biology and the History of Hip Hop
Event Handler
 
Tumours and Tree Trunks - GeekyScience: Evolution
Event Handler
 
Best Practice for UX Deliverables
Event Handler
 
The Missing Ingredient
Event Handler
 
Productivity quickly
Event Handler
 
Anna pickard geekyfinal
Event Handler
 
Ad

Recently uploaded (20)

PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Digital Circuits, important subject in CS
contactparinay1
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 

An Introduction to JavaScript: Week One