omg javascript

12
OMG JavaScript! Gennadii Potapov

Upload: gennadiy-potapov

Post on 15-May-2015

2.127 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: OMG JavaScript

OMG JavaScript!

Gennadii Potapov

Page 2: OMG JavaScript

About duck typing in dynamic languages:

“My god how you can write a real program when you just assigning random crap to another crap and expecting it to work”

– John Carmack, founder of id Software, developer of

popular game titles like Wolfenstein , Doom, Quake and Rage, well-known open source

advocate, millionaire.

Page 3: OMG JavaScript

JavaScript is really complicated language…

Page 4: OMG JavaScript

var a = 012console.log( a )

→ 10

OMG!

Page 5: OMG JavaScript

console.log( "3" + 1 )

→ "31"

console.log( "3" – 1 )

→ 2

OMG!!console.log( "222" - -"111" )

→ "333"

OMG!!!

Page 6: OMG JavaScript

console.log( 9999999999999999 )

→ 10000000000000000

OMG!!!!console.log( 111111111111111111111 )

→ 111111111111111110000

Page 7: OMG JavaScript

console.log( Math.max() )

→ -Infinity

console.log( Math.min() )

→ Infinity

console.log( new Array([], null, undefined, null) == ",,,"; )

→ true

var foo = [0];console.log(foo == !foo);console.log(foo == foo);

→ true→ true

Page 8: OMG JavaScript

console.log( 3.toString() )console.log( 3..toString() )

→ SyntaxError: identifier starts immediately after numeric literal → "3"

var a = new Number;console.log(a == 0)var a = new String;console.log(a == "")var a = new Object;console.log(a == {})var a = new Array;console.log(a == [])

→ true→ true→ false→ false

Page 9: OMG JavaScript

var a = {};console.log( a == {} );var a = [];console.log( a == [] );

→ false→ false

console.log( (!+[]+[]+![]) );

→ "truefalse"

console.log( (![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]] )

→ "fail"

Page 10: OMG JavaScript

console.log( {} + {} );

→ NaN

console.log( [] + [] );

→ ""

console.log( [] + {} );

→ "[object Object]"

console.log( {} + [] );

→ 0

console.log( 1 < 2 < 3 );console.log( 3 < 2 < 1);

→ true→ true

Page 11: OMG JavaScript

JavaScript. Just be smarter!

Page 12: OMG JavaScript

Links

WTF JavaScript: http://www.wtfjs.com/

Destroy All Software Screencasts:http://www.destroyallsoftware.com/

JavaScript Tutorial: http://www.javascript.info/

JavaScript Specification:http://www.ecma-international.org/publications/standards/Ecma-262.htm