omg javascript
TRANSCRIPT
OMG JavaScript!
Gennadii Potapov
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.
JavaScript is really complicated language…
var a = 012console.log( a )
→ 10
OMG!
console.log( "3" + 1 )
→ "31"
console.log( "3" – 1 )
→ 2
OMG!!console.log( "222" - -"111" )
→ "333"
OMG!!!
console.log( 9999999999999999 )
→ 10000000000000000
OMG!!!!console.log( 111111111111111111111 )
→ 111111111111111110000
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
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
var a = {};console.log( a == {} );var a = [];console.log( a == [] );
→ false→ false
console.log( (!+[]+[]+![]) );
→ "truefalse"
console.log( (![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]] )
→ "fail"
console.log( {} + {} );
→ NaN
console.log( [] + [] );
→ ""
console.log( [] + {} );
→ "[object Object]"
console.log( {} + [] );
→ 0
console.log( 1 < 2 < 3 );console.log( 3 < 2 < 1);
→ true→ true
JavaScript. Just be smarter!
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