SlideShare a Scribd company logo
JavaScript
Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
“Are you telling me that I can’t get away
anymore without getting deeply into Javascript?”

                                         - Developer
“That is a disaster for me! I have made a career
out of actively avoiding Javascript.”

                                         - Developer
“If I cant continue to ignore Javascript, then you
may as well amputate one of my limbs.”

                                           - Developer
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
// Variable declaration
var firstName = "Forrest";

// Function declaration
function saying () {
    return "Stupid is as stupid does";
}
// If statement
if (badGrades) {
    return "Mom sleeps with teacher";
}

// Switch statement
var age = 10,
    lifeState;
switch (age) {
    case 10:
        lifeState = "Young";
        break;
    case 60:
        lifeState = "Old";
        break;
}
// Object literal
var forrest = {
    firstName : "Forrest"
};

// Array literal
var forrestFriends = ["Bubba", "Lieutenant Dan"];
// Shorthand assignment
function (boxOfChocolates) {
    var life = boxOfChocolates || "Snickers bar";
}

// Ternary operators
(looking)? "I gotta find Bubba!" : "It's ok";
// Short-circuit logic
if (obj && obj.property) {
    obj.property = "Lieutenant Dan, I got you some ice cream";
}
JavaScript - Like a Box of Chocolates
string
number
boolean
null
undefined
object
Array
string
           Date
number
           function
boolean
           RegExp
null
undefined
object
// Variable declaration
var firstName = "Forrest";

// Function declaration
function party () {
    return "Stupid is as stupid does";
}

typeof firstName // string
typeof party // function
// Object declaration
var forrest = {
    firstName : "Forrest"
};

// Array declaration
var forrestFriends = ["Bubba", "Lieutenant Dan"];



typeof forrest // object
typeof forrestFriends // object
// Object declaration
var forrest = {
    firstName : "Forrest"
};

// Array declaration
var forrestFriends = ["Bubba", "Lieutenant Dan"];


forrest forrest // object // false
 typeof instanceof Array
forrestFriends instanceof object // true
 typeof forrestFriends // Array
JavaScript - Like a Box of Chocolates
// Various "false" values
var nullVal = null;
var undefinedVal = undefined;
var zeroVal = 0;
var falseVal = false;
var emptyString = "";

// All would equal false in an if-clause
if (emptyString) {
    // Would never go in here
}
JavaScript - Like a Box of Chocolates
“Coercion is the practice of forcing another party
to behave in an involuntary manner”

                                          - Wikipedia
// Assignment
var happy = true;

// Equality
if (7 == "7") {
    // true
}

// Identity
if (7 === "7") {
    // false
}
// Assignment
                               rci on
                             oe
var happy = true;
                           c
// Equality        Ty pe
if (7 == "7") {
    // true
}

// Identity
if (7 === "7") {
    // false
}
// Type coercion
var sum = "5" + 6 + 7; // 567
// Prevent type coercion
var sum = parseInt("5", 10) + 6 + 7; // 18
JavaScript - Like a Box of Chocolates
// Self-invoking functions
(function () {
    var investment = "Lieutenant Dan got me
invested in some kind of fruit company.";
})();
JavaScript - Like a Box of Chocolates
// Using arguments
function friends (friend1, friend2) {
    return friend1 + " & " + friend2;
}

// Lieutenant Dan & Bubba
friends("Lieutenant Dan", "Bubba");

// Lieutenant Dan & undefined
friends("Lieutenant Dan");
// Using the arguments collection
function friends () {
    var allFriends = [];
    for (var i=0, il=arguments.length; i<il; i++) {
        allFriends.push(arguments[i]);
    };
    return allFriends.join(" & ");
}

// Lieutenant Dan & Bubba
friends("Lieutenant Dan", "Bubba");

// Lieutenant Dan
friends("Lieutenant Dan");
JavaScript - Like a Box of Chocolates
// Object declaration
function Forrest () {
    this.firstName = "Forrest";
    this.lastName = "Gump";
}

var forrest = new Forrest();
// Object declaration, literal style
var forrest = {
    firstName : "Forrest",
    lastName : "Gump"
};
// Iterating over properties
for (var item in forrest) {
     console.log(item + ": " + forrest[item]);
}
// Object declaration
var forrest = {
    firstName : "Forrest"
};

// Safe check for property
if ("firstName" in forrest) {
    console.log(forrest.firstName);
}
JavaScript - Like a Box of Chocolates
// Object declaration
function ForrestAsChild {
    this.firstName = "Forrest";
};

// Method set via prototype
ForrestAsChild.prototype.runsFast = function () {
    return true;
};
// Object declaration
function ForrestAsGrownup {
    this.joinsArmy = true;
};

// Prototype for new object
ForrestAsGrownup.prototype = new ForrestAsChild;

// Method set via prototype
ForrestAsGrownup.prototype.ruinsBathrobe = function () {
    return "I think I ruined your roommate's bathrobe";
};
// Create an instance
var forrest = new ForrestAsGrownup();

// Returns "I think I ruined your roommate's bathrobe"
forrest.ruinsBathrobe();

// Returns true - from ForrestAsChild
forrest.runsFast();

// Fails
forrest.codesJavaScript();
forrest instance

ForrestAsGrownup

ForrestAsChild

Object
JavaScript - Like a Box of Chocolates
// Extending core JavaScript objects
if (typeof Array.prototype.push === "undefined") {
    Array.prototype.push = function () {
        for (var i=0, il=arguments.length; i<il; i++) {
            this[this.length] = arguments[i];
        };
        return this;
    }
}



var locations = ["Vietnam"];
locations.push("China", "White House");
// locations = ["Vietnam", "China", "White House"];
JavaScript - Like a Box of Chocolates
// Scope - global or local

// Global
var quote = "I had run for 3 years, 2 months,
14 days, and 16 hours."

function () {
    // Local
    var pantherParty = "I'm sorry I had to
fight in the middle of your Black Panther
party.";

    // Global
    question = "And so, you just ran?";
}
// Global
function meetingJFK () {
    var JFKQuestion = "Congratulations, how do
you feel?";

    // Local
    function forrestReply () {
        return "I gotta pee.";
    }

    return forrestReply();
}

meetingJFK(); // I gotta pee
forrestReply(); // Error: not accessible
// Controlling scope
function whoAmI () {
    return this.nodeName;
}

whoAmI(); // undefined
whoAmI.call(document, "Hello"); // #document
whoAmI.apply(document.body, ["Hello", "Greetings?"]); // BODY
JavaScript - Like a Box of Chocolates
JavaScript - Like a Box of Chocolates
// closures
function happens (what) {
    return function (verb) {
        return what + " " + verb;
    }
}

var action = happens("Shit");

action("happens"); // Shit happens
JavaScript - Like a Box of Chocolates
// closures
function happens (what) {
    return function (verb) {
        return what + " " + verb;
    }
}

var action = happens("Shit");

// Breaking it down
var action = function (verb) {
    return "Shit" + " " + verb;
};
// closures
function happens (what) {
    return function (verb) {
        return what + " " + verb;
    }
}

var action = happens("Shit");

// Breaking it down
var action = function (verb) {
    return "Shit" + " " + verb;
};
var link;
for (var i=0; i<3; i++) {
    link = document.createElement("a");
    link.innerHTML = "Link " + i;
    link.onclick = function () {
        alert("I am link " + i);
    };
    document.body.appendChild(link);
};
var link;
for (var i=0; i<3; i++) {
    link = document.createElement("a");
    link.innerHTML = "Link " + i;
    link.onclick = function (index) {
        return function () {
            alert("I am link " + index);
        };
    }(i);
    document.body.appendChild(link);
};
var link;
for (var i=0; i<3; i++) {
    link = document.createElement("a");
    link.innerHTML = "Link " + i;
    link.onclick = function (index) {
        return function () {
            alert("I am link " + index);
        };
    }(i);
    document.body.appendChild(link);
};
var link;
for (var i=0; i<3; i++) {
    link = document.createElement("a");
    link.innerHTML = "Link " + i;
    link.onclick = function (index) {
        return function () {
            alert("I am link " + index);
        };
    }(i);
    document.body.appendChild(link);
};
var link;
for (var i=0; i<3; i++) {
    link = document.createElement("a");
    link.innerHTML = "Link " + i;
    link.onclick = function (index) {
        return function () {
            alert("I am link " + index);
        };
    }(i);
    document.body.appendChild(link);
};
JavaScript - Like a Box of Chocolates
// Yahoo! JavaScript Module Pattern
var forrest = function () {
    var firstName = "Forrest";

       return {
           getFirstName : function () {
                return firstName;
           }
       };
}();

// Returns "Forrest"
forrest.getFirstName();
// Yahoo! JavaScript Module Pattern
var forrest = function () {
    var firstName = "Forrest",
        getFirstName = function () {
            return firstName;
        };

       return {
           getFirstName : getFirstName
       };
}();

// Returns "Forrest"
forrest.getFirstName();
JavaScript - Like a Box of Chocolates
// Namespacing
var Movie = {};

// Yahoo! JavaScript Module Pattern
Movie.forrest = function () {
    var lastName = "Gump";

       return {
           firstName : "Forrest",
           getFirstName : function () {
                return this.firstName;
           }
       };
}();
// Yahoo! JavaScript Module Pattern
Movie.forrest = function () {
    var lastName = "Gump";

       return {
           firstName : "Forrest",
           getFirstName : function () {
                return this.firstName;
           }
       };
}();



// Yahoo! JavaScript Module Pattern
Movie.lieutenantDan = function () {
    var lastName = "Taylor";

       return {
           firstName : "Dan",
           getFullName : function () {
                return Movie.forrest.getFirstName.call(this) + " " + lastName;
           }
       };
}();

Movie.lieutenantDan.getFullName();
// Yahoo! JavaScript Module Pattern
Movie.forrest = function () {
    var lastName = "Gump";

       return {
           firstName : "Forrest",
           getFirstName : function () {
                return this.firstName;
           }
       };
}();



// Yahoo! JavaScript Module Pattern
Movie.lieutenantDan = function () {
    var lastName = "Taylor";

       return {
           firstName : "Dan",
           getFullName : function () {
                return Movie.forrest.getFirstName.call(this) + " " + lastName;
           }
       };
}();

Movie.lieutenantDan.getFullName();
JavaScript - Like a Box of Chocolates
// Minimize DOM access
document.getElementById("container").className = "js-enabled";
document.getElementById("container").innerHTML += "Hello Amsterdam";
document.getElementById("container").innerHTML += "Tell me how you doin'!";
document.getElementById("container").innerHTML += "I went on a nice boat
                                                   ride last night!";
document.getElementById("container").innerHTML += "...where Carrot Top made
                                                   a pass at me...";
// Minimize DOM access
var container = document.getElementById("container"),
    content = "Hello Amsterdam";
container.className = "js-enabled";
content += "Tell me how you doin'!";
content += "I went on a nice boat ride last night!";
content += "...where Carrot Top made a pass at me...";
container.innerHTML = content;
// Minimize DOM access
var container = document.getElementById("container"),
    content = "Hello Amsterdam";
container.className = "js-enabled";
content += "Tell me how you doin'!";
content += "I went on a nice boat ride last night!";
content += "...where Carrot Top made a pass at me...";
container.innerHTML = content;
// Variable declaration
function richAndStupid () {
    var rich = "And cause I was a gazillionaire, I
cut that grass for free.",
        stupid = "Stupid is as stupid does.";
}
// Looping, variables and array lookups
function forrestForm () {
    var allParagraphs = document.getElementsByTagName("p");
    for (var i=0; i<allParagraphs.length; i++) {
        var link = document.createElement("a");
        link.href = "http://en.wikipedia.org/wiki/Forrest_Gump";
        link.title = "Read about Forrest Gump at Wikipedia";
        link.innerHTML = "Forrest Gump";

        allParagraphs[i].className = "Forrested";
        allParagraphs[i].appendChild(link);
    }
}
// Looping, variables and array lookups
function forrestForm () {
    var allParagraphs = document.getElementsByTagName("p");
    for (var i=0; i<allParagraphs.length; i++) {
        var link = document.createElement("a");
        link.href = "http://en.wikipedia.org/wiki/Forrest_Gump";
        link.title = "Read about Forrest Gump at Wikipedia";
        link.innerHTML = "Forrest Gump";

        allParagraphs[i].className = "Forrested";
        allParagraphs[i].appendChild(link);
    }
}
// Looping, variables and array lookups
function forrestForm () {
    var allParagraphs = document.getElementsByTagName("p");
    for (var i=0; i<allParagraphs.length; i++) {
        var link = document.createElement("a");
        link.href = "http://en.wikipedia.org/wiki/Forrest_Gump";
        link.title = "Read about Forrest Gump at Wikipedia";
        link.innerHTML = "Forrest Gump";

        allParagraphs[i].className = "Forrested";
        allParagraphs[i].appendChild(link);
    }
}
// Looping, variables and array lookups
function forrestForm () {
    var allParagraphs = document.getElementsByTagName("p");
    for (var i=0; i<allParagraphs.length; i++) {
        var link = document.createElement("a");
        link.href = "http://en.wikipedia.org/wiki/Forrest_Gump";
        link.title = "Read about Forrest Gump at Wikipedia";
        link.innerHTML = "Forrest Gump";

        allParagraphs[i].className = "Forrested";
        allParagraphs[i].appendChild(link);
    }
}
// Looping, variables and array lookups
function forrestForm () {
    var allParagraphs = document.getElementsByTagName("p");
    for (var i=0, l=allParagraphs.length, link, paragraph; i<l; i++) {
        link = document.createElement("a");
        link.href = "http://en.wikipedia.org/wiki/Forrest_Gump";
        link.title = "Read about Forrest Gump at Wikipedia";
        link.innerHTML = "Forrest Gump";

        paragraph = allParagraphs[i];
        paragraph.className = "Forrested";
        paragraph.appendChild(link);
    }
}
// Looping, variables and array lookups
function forrestForm () {
    var allParagraphs = document.getElementsByTagName("p");
    for (var i=0, l=allParagraphs.length, link, paragraph; i<l; i++) {
        link = document.createElement("a");
        link.href = "http://en.wikipedia.org/wiki/Forrest_Gump";
        link.title = "Read about Forrest Gump at Wikipedia";
        link.innerHTML = "Forrest Gump";

        paragraph = allParagraphs[i];
        paragraph.className = "Forrested";
        paragraph.appendChild(link);
    }
}
// Looping, variables and array lookups
function forrestForm () {
    var allParagraphs = document.getElementsByTagName("p");
    for (var i=0, l=allParagraphs.length, link, paragraph; i<l; i++) {
        link = document.createElement("a");
        link.href = "http://en.wikipedia.org/wiki/Forrest_Gump";
        link.title = "Read about Forrest Gump at Wikipedia";
        link.innerHTML = "Forrest Gump";

        paragraph = allParagraphs[i];
        paragraph.className = "Forrested";
        paragraph.appendChild(link);
    }
}
// Looping, variables and array lookups
function forrestForm () {
    var allParagraphs = document.getElementsByTagName("p");
    for (var i=0, l=allParagraphs.length, link, paragraph; i<l; i++) {
        link = document.createElement("a");
        link.href = "http://en.wikipedia.org/wiki/Forrest_Gump";
        link.title = "Read about Forrest Gump at Wikipedia";
        link.innerHTML = "Forrest Gump";

        paragraph = allParagraphs[i];
        paragraph.className = "Forrested";
        paragraph.appendChild(link);
    }
}
// Semicolon insertion
return
{
    javascript : "Fantastic!"
};
// Semicolon insertion
return; // Semicolon insertion
{ // Considered an empty block
    javascript : "Fantastic!"
}; // Semicolon insertion, dummy line
JSLint
JavaScript - Like a Box of Chocolates
Robert Nyman
                                                              http://robertnyman.com/speaking/

                                                                                Twitter: @robertnyman



Pictures:

Ninja Turtle: http://www.originalprop.com/blog/2008/03/20/teenage-mutant-ninja-turtles-costume-restoration/     Dog (Cat): http://www.cartoonstock.com/directory/f/false_identity.asp
Bruce Willis: http://www.starsjournal.com/3192/bruce-willis-is-being-sued-for-4-million-dollars.html            Hillary Clinton & Soldier: http://confederateyankee.mu.nu/archives/154032.php
Swedish flag: http://www.olssonfoto.se/JAlbum/SGP%202008%20Ullevi/slides/Svenska%20flaggan.html                   Play with yourself: http://www.justwhatshesaid.com/?p=965
Euro Coin: http://accidentaldong.blogspot.com/2009/10/euro-uh-oh.html                                           Overloading: http://theshadowhive.blogspot.com/2010/04/mutating-chaos-gene.html
                                                                                                                Brad Pitt: http://open.salon.com/blog/just-walt/2009/10/29/real_men_he-men_pictures_whos_the_manliest_of_men
                                                                                                                Kristen Bell: http://veronica-mars-episodes.download-tvshows.com/kristen-bell-loves-megan-fox/
Most popular language: http://odetocode.com/Blogs/scott/archive/2009/03/18/signs-that-your-javascript-skills-   Extensible table: http://www.amishshowroom.com/index.php?main_page=index&cPath=40_64
need-updating.aspx                                                                                              Tiger Woods: http://blogs.bigadda.com/pal4868546/2010/01/
Sunrise: http://www.manywallpapers.com/space-wallpapers/earth/sunrise-from-space.html                           Pollution: http://blog.lib.umn.edu/cramb005/architecture/
Astronaut: http://martianchronicles.wordpress.com/2009/01/23/carnival-of-space-87/                              Closure: http://today.msnbc.msn.com/id/4760120
Netscape 2: http://blog.explorelearning.com/2005/12/index.html                                                  Steve Ballmer: http://www.businessinsider.com/microsoft-completely-rebooted-its-mobile-strategy-yesterday-heres-
Internet Explorer 3: http://www.guidebookgallery.org/screenshots/browser                                        what-you-missed-2010-2
Gandalf: http://web.mit.edu/kayla/Public/Backgrounds/LOTR%20Gandalf%204.JPG                                     Inheritance: http://tithebarn.wordpress.com/2010/04/26/the-meek-shall-inherit-if-thats-alright-with-the-rest-of-you/
Now: http://www.geekologie.com/2007/07/15-week/                                                                 Crockford: http://gemsres.com/story/nov07/468365/Crockford_New_4681.jpg
Axe: http://bestgamewallpapers.com/a3-the-age-of-sovereign/axe                                                  Name: http://blog.usa.gov/roller/govgab/tags/names
Time: http://www.mindhacks.com/blog/seeing/index.html                                                           Space: http://gucken.deviantart.com/art/Sunrise-in-Space-56420137
Money: http://www.mediabistro.com/unbeige/ideas/                                                                Fail better: http://ozguralaz.posterous.com/ever-tried-ever-failed-no-matt
Happy Ape: http://thesituationist.wordpress.com/2007/06/14/
High speed train: http://www.freefoto.com/preview/23-22-1?ffid=23-22-1                                           Mila & Macaulay: http://uk.eonline.com/uberblog/b61889_mila_macaulay_home_alone.html
Sunspider results: http://ie.microsoft.com/testdrive/benchmarks/sunspider/default.html                          Hearts: http://www.funonthenet.in/content/view/395/31/
Forrest Gump: http://wallpaper-s.org/36__Forrest_Gump,_1994,_Tom_Hanks,_Robin_Wright_Penn.htm
Data: http://walrus.wr.usgs.gov/infobank/programs/html/definition/datadictionary.html
JavaScript - Like a Box of Chocolates

More Related Content

What's hot (20)

PDF
JavaScript Patterns
Giordano Scalzo
 
PDF
Monads asking the right question
Pawel Szulc
 
PDF
dojo.things()
Peter Higgins
 
PDF
Coffeescript: No really, it's just Javascript
Brian Mann
 
PDF
has("builds")
Peter Higgins
 
KEY
Lithium Best
Richard McIntyre
 
PDF
Java Puzzlers NG as it was presented at Detroit Java User Group
Baruch Sadogursky
 
PDF
#SPUG - Legacy applications
Piotr Pasich
 
PDF
Ember background basics
Philipp Fehre
 
PDF
Legacy applications - 4Developes konferencja, Piotr Pasich
Piotr Pasich
 
PDF
a hands on guide to django
swee meng ng
 
PDF
Functional Programming & Event Sourcing - a pair made in heaven
Pawel Szulc
 
PDF
Intro programacion funcional
NSCoder Mexico
 
KEY
Counting on God
James Gray
 
PPSX
Symfony2 meets propel 1.5
Francois Zaninotto
 
PPT
Advanced JavaScript
Stoyan Stefanov
 
PDF
The jQuery Divide
Rebecca Murphey
 
PDF
Javascript the New Parts v2
Federico Galassi
 
PDF
The report of JavaOne2011 about groovy
Yasuharu Nakano
 
PDF
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
JavaScript Patterns
Giordano Scalzo
 
Monads asking the right question
Pawel Szulc
 
dojo.things()
Peter Higgins
 
Coffeescript: No really, it's just Javascript
Brian Mann
 
has("builds")
Peter Higgins
 
Lithium Best
Richard McIntyre
 
Java Puzzlers NG as it was presented at Detroit Java User Group
Baruch Sadogursky
 
#SPUG - Legacy applications
Piotr Pasich
 
Ember background basics
Philipp Fehre
 
Legacy applications - 4Developes konferencja, Piotr Pasich
Piotr Pasich
 
a hands on guide to django
swee meng ng
 
Functional Programming & Event Sourcing - a pair made in heaven
Pawel Szulc
 
Intro programacion funcional
NSCoder Mexico
 
Counting on God
James Gray
 
Symfony2 meets propel 1.5
Francois Zaninotto
 
Advanced JavaScript
Stoyan Stefanov
 
The jQuery Divide
Rebecca Murphey
 
Javascript the New Parts v2
Federico Galassi
 
The report of JavaOne2011 about groovy
Yasuharu Nakano
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 

Viewers also liked (6)

PDF
The prestige of being a web developer (no notes)
Christian Heilmann
 
PDF
Yi Yang_Resume
Yi Yang
 
PDF
2016_Jan_Resume_Lyra
敏宽 晏
 
PDF
Resume_CS
Yunzhe Pan
 
PDF
Huu Bang's Résumé
Huu Bang Le Phan
 
PDF
Zhen li Resume
Zhen Li
 
The prestige of being a web developer (no notes)
Christian Heilmann
 
Yi Yang_Resume
Yi Yang
 
2016_Jan_Resume_Lyra
敏宽 晏
 
Resume_CS
Yunzhe Pan
 
Huu Bang's Résumé
Huu Bang Le Phan
 
Zhen li Resume
Zhen Li
 
Ad

Similar to JavaScript - Like a Box of Chocolates (20)

PDF
JavaScript - Like a Box of Chocolates - jsDay
Robert Nyman
 
PDF
JavaScript & HTML5 - Brave New World
Robert Nyman
 
PDF
JavaScript and HTML5 - Brave New World (revised)
Robert Nyman
 
KEY
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
KEY
JavaScript @ CTK
Jakob Mattsson
 
PPT
JavaScript - Programming Languages course
yoavrubin
 
PDF
JavaScript Primer
Daniel Cousineau
 
PPT
Wakanday JS201 Best Practices
Juergen Fesslmeier
 
PPTX
Awesomeness of JavaScript…almost
Quinton Sheppard
 
PDF
The many facets of code reuse in JavaScript
Leonardo Borges
 
PDF
Intro to Advanced JavaScript
ryanstout
 
PPT
JavaScript Needn't Hurt!
Thomas Kjeldahl Nilsson
 
KEY
Javascript tid-bits
David Atchley
 
KEY
Week3
Will Gaybrick
 
PPT
Object Oriented JavaScript
Donald Sipe
 
PDF
Say It With Javascript
Giovanni Scerra ☃
 
PPTX
Java Script basics and DOM
Sukrit Gupta
 
PDF
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 
PPTX
Java script
Sukrit Gupta
 
JavaScript - Like a Box of Chocolates - jsDay
Robert Nyman
 
JavaScript & HTML5 - Brave New World
Robert Nyman
 
JavaScript and HTML5 - Brave New World (revised)
Robert Nyman
 
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
JavaScript @ CTK
Jakob Mattsson
 
JavaScript - Programming Languages course
yoavrubin
 
JavaScript Primer
Daniel Cousineau
 
Wakanday JS201 Best Practices
Juergen Fesslmeier
 
Awesomeness of JavaScript…almost
Quinton Sheppard
 
The many facets of code reuse in JavaScript
Leonardo Borges
 
Intro to Advanced JavaScript
ryanstout
 
JavaScript Needn't Hurt!
Thomas Kjeldahl Nilsson
 
Javascript tid-bits
David Atchley
 
Object Oriented JavaScript
Donald Sipe
 
Say It With Javascript
Giovanni Scerra ☃
 
Java Script basics and DOM
Sukrit Gupta
 
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 
Java script
Sukrit Gupta
 
Ad

More from Robert Nyman (20)

PDF
Have you tried listening?
Robert Nyman
 
PDF
Building for Your Next Billion - Google I/O 2017
Robert Nyman
 
PDF
Introduction to Google Daydream
Robert Nyman
 
PDF
Predictability for the Web
Robert Nyman
 
PDF
The Future of Progressive Web Apps - View Source conference, Berlin 2016
Robert Nyman
 
PDF
The Future of the Web - Cold Front conference 2016
Robert Nyman
 
PDF
The Future of Progressive Web Apps - Google for Indonesia
Robert Nyman
 
PDF
Google tech & products
Robert Nyman
 
PDF
Introduction to Progressive Web Apps, Google Developer Summit, Seoul - South ...
Robert Nyman
 
PDF
Progressive Web Apps keynote, Google Developer Summit, Tokyo, Japan
Robert Nyman
 
PDF
The web - What it has, what it lacks and where it must go - keynote at Riga D...
Robert Nyman
 
PDF
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
Robert Nyman
 
PDF
The web - What it has, what it lacks and where it must go - Istanbul
Robert Nyman
 
PDF
The web - What it has, what it lacks and where it must go
Robert Nyman
 
PDF
Google, the future and possibilities
Robert Nyman
 
PDF
Developer Relations in the Nordics
Robert Nyman
 
PDF
What is Developer Relations?
Robert Nyman
 
PDF
Android TV Introduction - Stockholm Android TV meetup
Robert Nyman
 
PDF
New improvements for web developers - frontend.fi, Helsinki
Robert Nyman
 
PDF
Mobile phone trends, user data & developer climate - frontend.fi, Helsinki
Robert Nyman
 
Have you tried listening?
Robert Nyman
 
Building for Your Next Billion - Google I/O 2017
Robert Nyman
 
Introduction to Google Daydream
Robert Nyman
 
Predictability for the Web
Robert Nyman
 
The Future of Progressive Web Apps - View Source conference, Berlin 2016
Robert Nyman
 
The Future of the Web - Cold Front conference 2016
Robert Nyman
 
The Future of Progressive Web Apps - Google for Indonesia
Robert Nyman
 
Google tech & products
Robert Nyman
 
Introduction to Progressive Web Apps, Google Developer Summit, Seoul - South ...
Robert Nyman
 
Progressive Web Apps keynote, Google Developer Summit, Tokyo, Japan
Robert Nyman
 
The web - What it has, what it lacks and where it must go - keynote at Riga D...
Robert Nyman
 
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
Robert Nyman
 
The web - What it has, what it lacks and where it must go - Istanbul
Robert Nyman
 
The web - What it has, what it lacks and where it must go
Robert Nyman
 
Google, the future and possibilities
Robert Nyman
 
Developer Relations in the Nordics
Robert Nyman
 
What is Developer Relations?
Robert Nyman
 
Android TV Introduction - Stockholm Android TV meetup
Robert Nyman
 
New improvements for web developers - frontend.fi, Helsinki
Robert Nyman
 
Mobile phone trends, user data & developer climate - frontend.fi, Helsinki
Robert Nyman
 

Recently uploaded (20)

PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 

JavaScript - Like a Box of Chocolates

  • 1. JavaScript Like a Box of Chocolates
  • 15. “Are you telling me that I can’t get away anymore without getting deeply into Javascript?” - Developer
  • 16. “That is a disaster for me! I have made a career out of actively avoiding Javascript.” - Developer
  • 17. “If I cant continue to ignore Javascript, then you may as well amputate one of my limbs.” - Developer
  • 24. // Variable declaration var firstName = "Forrest"; // Function declaration function saying () { return "Stupid is as stupid does"; }
  • 25. // If statement if (badGrades) { return "Mom sleeps with teacher"; } // Switch statement var age = 10, lifeState; switch (age) { case 10: lifeState = "Young"; break; case 60: lifeState = "Old"; break; }
  • 26. // Object literal var forrest = { firstName : "Forrest" }; // Array literal var forrestFriends = ["Bubba", "Lieutenant Dan"];
  • 27. // Shorthand assignment function (boxOfChocolates) { var life = boxOfChocolates || "Snickers bar"; } // Ternary operators (looking)? "I gotta find Bubba!" : "It's ok";
  • 28. // Short-circuit logic if (obj && obj.property) { obj.property = "Lieutenant Dan, I got you some ice cream"; }
  • 31. Array string Date number function boolean RegExp null undefined object
  • 32. // Variable declaration var firstName = "Forrest"; // Function declaration function party () { return "Stupid is as stupid does"; } typeof firstName // string typeof party // function
  • 33. // Object declaration var forrest = { firstName : "Forrest" }; // Array declaration var forrestFriends = ["Bubba", "Lieutenant Dan"]; typeof forrest // object typeof forrestFriends // object
  • 34. // Object declaration var forrest = { firstName : "Forrest" }; // Array declaration var forrestFriends = ["Bubba", "Lieutenant Dan"]; forrest forrest // object // false typeof instanceof Array forrestFriends instanceof object // true typeof forrestFriends // Array
  • 36. // Various "false" values var nullVal = null; var undefinedVal = undefined; var zeroVal = 0; var falseVal = false; var emptyString = ""; // All would equal false in an if-clause if (emptyString) { // Would never go in here }
  • 38. “Coercion is the practice of forcing another party to behave in an involuntary manner” - Wikipedia
  • 39. // Assignment var happy = true; // Equality if (7 == "7") { // true } // Identity if (7 === "7") { // false }
  • 40. // Assignment rci on oe var happy = true; c // Equality Ty pe if (7 == "7") { // true } // Identity if (7 === "7") { // false }
  • 41. // Type coercion var sum = "5" + 6 + 7; // 567
  • 42. // Prevent type coercion var sum = parseInt("5", 10) + 6 + 7; // 18
  • 44. // Self-invoking functions (function () { var investment = "Lieutenant Dan got me invested in some kind of fruit company."; })();
  • 46. // Using arguments function friends (friend1, friend2) { return friend1 + " & " + friend2; } // Lieutenant Dan & Bubba friends("Lieutenant Dan", "Bubba"); // Lieutenant Dan & undefined friends("Lieutenant Dan");
  • 47. // Using the arguments collection function friends () { var allFriends = []; for (var i=0, il=arguments.length; i<il; i++) { allFriends.push(arguments[i]); }; return allFriends.join(" & "); } // Lieutenant Dan & Bubba friends("Lieutenant Dan", "Bubba"); // Lieutenant Dan friends("Lieutenant Dan");
  • 49. // Object declaration function Forrest () { this.firstName = "Forrest"; this.lastName = "Gump"; } var forrest = new Forrest();
  • 50. // Object declaration, literal style var forrest = { firstName : "Forrest", lastName : "Gump" };
  • 51. // Iterating over properties for (var item in forrest) { console.log(item + ": " + forrest[item]); }
  • 52. // Object declaration var forrest = { firstName : "Forrest" }; // Safe check for property if ("firstName" in forrest) { console.log(forrest.firstName); }
  • 54. // Object declaration function ForrestAsChild { this.firstName = "Forrest"; }; // Method set via prototype ForrestAsChild.prototype.runsFast = function () { return true; };
  • 55. // Object declaration function ForrestAsGrownup { this.joinsArmy = true; }; // Prototype for new object ForrestAsGrownup.prototype = new ForrestAsChild; // Method set via prototype ForrestAsGrownup.prototype.ruinsBathrobe = function () { return "I think I ruined your roommate's bathrobe"; };
  • 56. // Create an instance var forrest = new ForrestAsGrownup(); // Returns "I think I ruined your roommate's bathrobe" forrest.ruinsBathrobe(); // Returns true - from ForrestAsChild forrest.runsFast(); // Fails forrest.codesJavaScript();
  • 59. // Extending core JavaScript objects if (typeof Array.prototype.push === "undefined") { Array.prototype.push = function () { for (var i=0, il=arguments.length; i<il; i++) { this[this.length] = arguments[i]; }; return this; } } var locations = ["Vietnam"]; locations.push("China", "White House"); // locations = ["Vietnam", "China", "White House"];
  • 61. // Scope - global or local // Global var quote = "I had run for 3 years, 2 months, 14 days, and 16 hours." function () { // Local var pantherParty = "I'm sorry I had to fight in the middle of your Black Panther party."; // Global question = "And so, you just ran?"; }
  • 62. // Global function meetingJFK () { var JFKQuestion = "Congratulations, how do you feel?"; // Local function forrestReply () { return "I gotta pee."; } return forrestReply(); } meetingJFK(); // I gotta pee forrestReply(); // Error: not accessible
  • 63. // Controlling scope function whoAmI () { return this.nodeName; } whoAmI(); // undefined whoAmI.call(document, "Hello"); // #document whoAmI.apply(document.body, ["Hello", "Greetings?"]); // BODY
  • 66. // closures function happens (what) { return function (verb) { return what + " " + verb; } } var action = happens("Shit"); action("happens"); // Shit happens
  • 68. // closures function happens (what) { return function (verb) { return what + " " + verb; } } var action = happens("Shit"); // Breaking it down var action = function (verb) { return "Shit" + " " + verb; };
  • 69. // closures function happens (what) { return function (verb) { return what + " " + verb; } } var action = happens("Shit"); // Breaking it down var action = function (verb) { return "Shit" + " " + verb; };
  • 70. var link; for (var i=0; i<3; i++) { link = document.createElement("a"); link.innerHTML = "Link " + i; link.onclick = function () { alert("I am link " + i); }; document.body.appendChild(link); };
  • 71. var link; for (var i=0; i<3; i++) { link = document.createElement("a"); link.innerHTML = "Link " + i; link.onclick = function (index) { return function () { alert("I am link " + index); }; }(i); document.body.appendChild(link); };
  • 72. var link; for (var i=0; i<3; i++) { link = document.createElement("a"); link.innerHTML = "Link " + i; link.onclick = function (index) { return function () { alert("I am link " + index); }; }(i); document.body.appendChild(link); };
  • 73. var link; for (var i=0; i<3; i++) { link = document.createElement("a"); link.innerHTML = "Link " + i; link.onclick = function (index) { return function () { alert("I am link " + index); }; }(i); document.body.appendChild(link); };
  • 74. var link; for (var i=0; i<3; i++) { link = document.createElement("a"); link.innerHTML = "Link " + i; link.onclick = function (index) { return function () { alert("I am link " + index); }; }(i); document.body.appendChild(link); };
  • 76. // Yahoo! JavaScript Module Pattern var forrest = function () { var firstName = "Forrest"; return { getFirstName : function () { return firstName; } }; }(); // Returns "Forrest" forrest.getFirstName();
  • 77. // Yahoo! JavaScript Module Pattern var forrest = function () { var firstName = "Forrest", getFirstName = function () { return firstName; }; return { getFirstName : getFirstName }; }(); // Returns "Forrest" forrest.getFirstName();
  • 79. // Namespacing var Movie = {}; // Yahoo! JavaScript Module Pattern Movie.forrest = function () { var lastName = "Gump"; return { firstName : "Forrest", getFirstName : function () { return this.firstName; } }; }();
  • 80. // Yahoo! JavaScript Module Pattern Movie.forrest = function () { var lastName = "Gump"; return { firstName : "Forrest", getFirstName : function () { return this.firstName; } }; }(); // Yahoo! JavaScript Module Pattern Movie.lieutenantDan = function () { var lastName = "Taylor"; return { firstName : "Dan", getFullName : function () { return Movie.forrest.getFirstName.call(this) + " " + lastName; } }; }(); Movie.lieutenantDan.getFullName();
  • 81. // Yahoo! JavaScript Module Pattern Movie.forrest = function () { var lastName = "Gump"; return { firstName : "Forrest", getFirstName : function () { return this.firstName; } }; }(); // Yahoo! JavaScript Module Pattern Movie.lieutenantDan = function () { var lastName = "Taylor"; return { firstName : "Dan", getFullName : function () { return Movie.forrest.getFirstName.call(this) + " " + lastName; } }; }(); Movie.lieutenantDan.getFullName();
  • 83. // Minimize DOM access document.getElementById("container").className = "js-enabled"; document.getElementById("container").innerHTML += "Hello Amsterdam"; document.getElementById("container").innerHTML += "Tell me how you doin'!"; document.getElementById("container").innerHTML += "I went on a nice boat ride last night!"; document.getElementById("container").innerHTML += "...where Carrot Top made a pass at me...";
  • 84. // Minimize DOM access var container = document.getElementById("container"), content = "Hello Amsterdam"; container.className = "js-enabled"; content += "Tell me how you doin'!"; content += "I went on a nice boat ride last night!"; content += "...where Carrot Top made a pass at me..."; container.innerHTML = content;
  • 85. // Minimize DOM access var container = document.getElementById("container"), content = "Hello Amsterdam"; container.className = "js-enabled"; content += "Tell me how you doin'!"; content += "I went on a nice boat ride last night!"; content += "...where Carrot Top made a pass at me..."; container.innerHTML = content;
  • 86. // Variable declaration function richAndStupid () { var rich = "And cause I was a gazillionaire, I cut that grass for free.", stupid = "Stupid is as stupid does."; }
  • 87. // Looping, variables and array lookups function forrestForm () { var allParagraphs = document.getElementsByTagName("p"); for (var i=0; i<allParagraphs.length; i++) { var link = document.createElement("a"); link.href = "http://en.wikipedia.org/wiki/Forrest_Gump"; link.title = "Read about Forrest Gump at Wikipedia"; link.innerHTML = "Forrest Gump"; allParagraphs[i].className = "Forrested"; allParagraphs[i].appendChild(link); } }
  • 88. // Looping, variables and array lookups function forrestForm () { var allParagraphs = document.getElementsByTagName("p"); for (var i=0; i<allParagraphs.length; i++) { var link = document.createElement("a"); link.href = "http://en.wikipedia.org/wiki/Forrest_Gump"; link.title = "Read about Forrest Gump at Wikipedia"; link.innerHTML = "Forrest Gump"; allParagraphs[i].className = "Forrested"; allParagraphs[i].appendChild(link); } }
  • 89. // Looping, variables and array lookups function forrestForm () { var allParagraphs = document.getElementsByTagName("p"); for (var i=0; i<allParagraphs.length; i++) { var link = document.createElement("a"); link.href = "http://en.wikipedia.org/wiki/Forrest_Gump"; link.title = "Read about Forrest Gump at Wikipedia"; link.innerHTML = "Forrest Gump"; allParagraphs[i].className = "Forrested"; allParagraphs[i].appendChild(link); } }
  • 90. // Looping, variables and array lookups function forrestForm () { var allParagraphs = document.getElementsByTagName("p"); for (var i=0; i<allParagraphs.length; i++) { var link = document.createElement("a"); link.href = "http://en.wikipedia.org/wiki/Forrest_Gump"; link.title = "Read about Forrest Gump at Wikipedia"; link.innerHTML = "Forrest Gump"; allParagraphs[i].className = "Forrested"; allParagraphs[i].appendChild(link); } }
  • 91. // Looping, variables and array lookups function forrestForm () { var allParagraphs = document.getElementsByTagName("p"); for (var i=0, l=allParagraphs.length, link, paragraph; i<l; i++) { link = document.createElement("a"); link.href = "http://en.wikipedia.org/wiki/Forrest_Gump"; link.title = "Read about Forrest Gump at Wikipedia"; link.innerHTML = "Forrest Gump"; paragraph = allParagraphs[i]; paragraph.className = "Forrested"; paragraph.appendChild(link); } }
  • 92. // Looping, variables and array lookups function forrestForm () { var allParagraphs = document.getElementsByTagName("p"); for (var i=0, l=allParagraphs.length, link, paragraph; i<l; i++) { link = document.createElement("a"); link.href = "http://en.wikipedia.org/wiki/Forrest_Gump"; link.title = "Read about Forrest Gump at Wikipedia"; link.innerHTML = "Forrest Gump"; paragraph = allParagraphs[i]; paragraph.className = "Forrested"; paragraph.appendChild(link); } }
  • 93. // Looping, variables and array lookups function forrestForm () { var allParagraphs = document.getElementsByTagName("p"); for (var i=0, l=allParagraphs.length, link, paragraph; i<l; i++) { link = document.createElement("a"); link.href = "http://en.wikipedia.org/wiki/Forrest_Gump"; link.title = "Read about Forrest Gump at Wikipedia"; link.innerHTML = "Forrest Gump"; paragraph = allParagraphs[i]; paragraph.className = "Forrested"; paragraph.appendChild(link); } }
  • 94. // Looping, variables and array lookups function forrestForm () { var allParagraphs = document.getElementsByTagName("p"); for (var i=0, l=allParagraphs.length, link, paragraph; i<l; i++) { link = document.createElement("a"); link.href = "http://en.wikipedia.org/wiki/Forrest_Gump"; link.title = "Read about Forrest Gump at Wikipedia"; link.innerHTML = "Forrest Gump"; paragraph = allParagraphs[i]; paragraph.className = "Forrested"; paragraph.appendChild(link); } }
  • 95. // Semicolon insertion return { javascript : "Fantastic!" };
  • 96. // Semicolon insertion return; // Semicolon insertion { // Considered an empty block javascript : "Fantastic!" }; // Semicolon insertion, dummy line
  • 99. Robert Nyman http://robertnyman.com/speaking/ Twitter: @robertnyman Pictures: Ninja Turtle: http://www.originalprop.com/blog/2008/03/20/teenage-mutant-ninja-turtles-costume-restoration/ Dog (Cat): http://www.cartoonstock.com/directory/f/false_identity.asp Bruce Willis: http://www.starsjournal.com/3192/bruce-willis-is-being-sued-for-4-million-dollars.html Hillary Clinton & Soldier: http://confederateyankee.mu.nu/archives/154032.php Swedish flag: http://www.olssonfoto.se/JAlbum/SGP%202008%20Ullevi/slides/Svenska%20flaggan.html Play with yourself: http://www.justwhatshesaid.com/?p=965 Euro Coin: http://accidentaldong.blogspot.com/2009/10/euro-uh-oh.html Overloading: http://theshadowhive.blogspot.com/2010/04/mutating-chaos-gene.html Brad Pitt: http://open.salon.com/blog/just-walt/2009/10/29/real_men_he-men_pictures_whos_the_manliest_of_men Kristen Bell: http://veronica-mars-episodes.download-tvshows.com/kristen-bell-loves-megan-fox/ Most popular language: http://odetocode.com/Blogs/scott/archive/2009/03/18/signs-that-your-javascript-skills- Extensible table: http://www.amishshowroom.com/index.php?main_page=index&cPath=40_64 need-updating.aspx Tiger Woods: http://blogs.bigadda.com/pal4868546/2010/01/ Sunrise: http://www.manywallpapers.com/space-wallpapers/earth/sunrise-from-space.html Pollution: http://blog.lib.umn.edu/cramb005/architecture/ Astronaut: http://martianchronicles.wordpress.com/2009/01/23/carnival-of-space-87/ Closure: http://today.msnbc.msn.com/id/4760120 Netscape 2: http://blog.explorelearning.com/2005/12/index.html Steve Ballmer: http://www.businessinsider.com/microsoft-completely-rebooted-its-mobile-strategy-yesterday-heres- Internet Explorer 3: http://www.guidebookgallery.org/screenshots/browser what-you-missed-2010-2 Gandalf: http://web.mit.edu/kayla/Public/Backgrounds/LOTR%20Gandalf%204.JPG Inheritance: http://tithebarn.wordpress.com/2010/04/26/the-meek-shall-inherit-if-thats-alright-with-the-rest-of-you/ Now: http://www.geekologie.com/2007/07/15-week/ Crockford: http://gemsres.com/story/nov07/468365/Crockford_New_4681.jpg Axe: http://bestgamewallpapers.com/a3-the-age-of-sovereign/axe Name: http://blog.usa.gov/roller/govgab/tags/names Time: http://www.mindhacks.com/blog/seeing/index.html Space: http://gucken.deviantart.com/art/Sunrise-in-Space-56420137 Money: http://www.mediabistro.com/unbeige/ideas/ Fail better: http://ozguralaz.posterous.com/ever-tried-ever-failed-no-matt Happy Ape: http://thesituationist.wordpress.com/2007/06/14/ High speed train: http://www.freefoto.com/preview/23-22-1?ffid=23-22-1 Mila & Macaulay: http://uk.eonline.com/uberblog/b61889_mila_macaulay_home_alone.html Sunspider results: http://ie.microsoft.com/testdrive/benchmarks/sunspider/default.html Hearts: http://www.funonthenet.in/content/view/395/31/ Forrest Gump: http://wallpaper-s.org/36__Forrest_Gump,_1994,_Tom_Hanks,_Robin_Wright_Penn.htm Data: http://walrus.wr.usgs.gov/infobank/programs/html/definition/datadictionary.html