Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Códigos para lightning talk "javascript: alinguagem do capeta"
//////////////////////////////////////// - 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
You can’t perform that action at this time.