Last active
August 29, 2015 14:08
-
-
Save paulodeleo/481bd97948fc9c79765c to your computer and use it in GitHub Desktop.
Códigos para lightning talk "javascript: alinguagem do capeta"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////// - 0: introdução | |
0.1 + 0.2 // 0.30000000000000004 | |
(0.1+0.2).toFixed(2) // "0.30" | |
42.toFixed(2); // SyntaxError: | |
42.888.toFixed(2); // "42.89" | |
42..toFixed(2); // "42.00" | |
0.1+0.2.toFixed(2) // "0.10.20" | |
(42).toFixed(2); // "42.00" | |
//////////////////////////////////////// - 1: undefined & typeof | |
a // error: undefined | |
typeof(a) // 'undefined' | |
//////////////////////////////////////// - 2: array & length | |
Array(3).length | |
Array(3).forEach(function(index, element){console.log(index)}) | |
[undefined, undefined, undefined].forEach(function(element, index){console.log(index)}) | |
//////////////////////////////////////// - 3: Object & instanceof & constructor & NaN | |
Object() instanceof Object | |
{} instanceof Object // error | |
({}) instanceof Object | |
(((({})))) instanceof Object | |
[] instanceof Object | |
Object instanceof Object | |
Object().constructor == Object // true | |
Object().constructor == Array // false | |
typeof([]) == 'object' // true | |
typeof([]) == 'array' // false | |
0/0 // NaN | |
typeof(NaN) // number | |
//////////////////////////////////////// - 4: array & length & undefined | |
, // syntax error | |
[,] // [undefined x 1] | |
[,,,].length // 3 | |
[undefined,undefined,undefined] == [,,,] // false | |
[undefined,undefined,undefined] == ',,' // true | |
[[],null,undefined,null] == ",,," // true | |
//////////////////////////////////////// - 5: apenas uma dessas dá true | |
null == true // false | |
null == false // false | |
!null == true // true | |
!null == false // false | |
//////////////////////////////////////// - 6: apenas uma dessas dá false | |
a = [] | |
a == a // true | |
a == !a // true | |
[] == [] // false | |
[] == ![] // true | |
//////////////////////////////////////// - 7: magic number | |
9999999999999999 | |
9999999999999999 == 10000000000000000 | |
9999999999999999 - 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment