Skip to content

Instantly share code, notes, and snippets.

@juliankrispel
Last active December 14, 2015 09:18
Show Gist options
  • Select an option

  • Save juliankrispel/5063705 to your computer and use it in GitHub Desktop.

Select an option

Save juliankrispel/5063705 to your computer and use it in GitHub Desktop.
Javascript Quirks

#JS Quirks!

##Underscore Extending an Object with _.extend doesn't extend the actual function body

Everybody expects Javascript to fail when you do this: (A typo basically)

var a = 0,
    b = 1,
    c = 2;
    d = 3,
    e = 4;

But an expression in a serial variable declaration ending with a semicolon works.

var a = 0,
    b = 1,
    c = 1 || 2 || 3;
    d = 2,
    e = 3;

##WTF Truesy False!

[] == true // false

if([]) return true // true

##New Object only links to variables:

var obj = obj 2 = new Object({ name: 'John' });
obj.name = 'Sarah' // obj2.name changes too

##Dot Syntax in String?

var obj = {}
obj['admin.name'] = 'Julian'
return obj; // Outputs obj: { 'admin.name' : 'Julian' } I'd expect dots in propertyNames to be forbidden since it's confusing.

##function arguments act like a variable

var func = function(arg){
    for( x = 0; i < 3; i++){
        console.log(arg);
        arg = 0;
    }
}
func();

Prints:

undefined
0
0

##Numbers

We all know ridiculous floating points right?

0.1 + 0.2 // 0.30000000000000004

Ever tried leading zeros?

010 + 010 // 16
10.2 + 010 // 18.2 <- WTFFFFFFFF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment