Skip to content

Instantly share code, notes, and snippets.

@brendomaciel
Last active November 6, 2016 01:06
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save brendomaciel/a821a143c3c53433f0c5cd048b030ca6 to your computer and use it in GitHub Desktop.
Save brendomaciel/a821a143c3c53433f0c5cd048b030ca6 to your computer and use it in GitHub Desktop.
JavaScript "Stranger Things"

JavaScript "Stranger Things"

O JavaScript possui uma série de curiosidades em relação a algumas instruções. Portanto, tome cuidado se precisar utilizar qualquer uma dessas instruções listadas abaixo.

0.1 + 0.2 == 0.3 // false

1 / 0 // Infinity

-1 / 0 // -Infinity

0 / -1 // -0

0 == -0 // true

++Math.PI // 4.141592653589793

var a = 1 / "a" // NaN
var b = "b" // "b"
isNaN(a) // true
isNaN(b) // true

NaN == NaN // false

typeof NaN // "number"

typeof ([[], {}] + []) // "string"

~null // -1

[5*5] - 1 * [] // 25

[12, 2, 1].sort() // [1, 12, 2]

[] + [] // ""

[] * [] // 0

[] + {} // "[object Object]"

{} + [] // 0

{} - [] // -0

{} + {} // "[object Object][object Object]"

JSON.stringify({regex: /a/}) // "{"regex":{}}"

document.querySelector('elemento qualquer').attributes[0] + "" // "[object Attr]"

Obs.: Instruções que usam DOM, obviamente, não funcionam no NodeJS.

O fato de o retorno não ser esperado ou óbvio, não quer dizer que, necessariamente, ele seja um bug ou algo que passou despercebido pelas pessoas que matêm a linguagem e/ou interpretadores.

@wggley
Copy link

wggley commented Sep 22, 2016

@wggley
Copy link

wggley commented Sep 22, 2016

"que passou despercebido pelas pessoas que mantém a linguagem e/ou interpretadores."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment