Skip to content

Instantly share code, notes, and snippets.

@piratefsh
Last active October 20, 2017 16:23
Show Gist options
  • Save piratefsh/b9da7850c7b21f6d7d5a to your computer and use it in GitHub Desktop.
Save piratefsh/b9da7850c7b21f6d7d5a to your computer and use it in GitHub Desktop.

JavaScript, the weird parts

JavaScript can be mysterious and weird, let's just all admit that. In this talk, we'll explore all the wonderful obscure, weird bits of JavaScript, and how to befriend them so they don't bite you in the ass (if they haven't already). For example we'll explore things like:

Why on earth does this work:

foo();

function foo(){
    console.log('foo');
}

...but this doesn't?

foo(); // throws TypeError: foo is not a function

var foo = function(){
    console.log('foo');
}

Why is my 'this' object all wrong when my callback runs?

This probably doesn't do what you want it to:

for(var i = 0; i < 4; i++){
    setTimeout(function(){
        console.log(i);
    }, 0)
}

// expected 0, 1, 2, 3
// but outputs 4, 4, 4, 4???

What the heck is a 'prototype', anyway?

And finally, why JavaScript, whyyyy?

> null == true
false

> null == false
false // wtf?

Bring your laptop for fun play-along, or just kick back and relax. Feel free to bring along your favourite JavaScript problems and we'll work on them!

p/s: Required watching for more fun JavaScript weirdness: https://www.destroyallsoftware.com/talks/wat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment