Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipsimoes/8fd59af763b752c08407f12ed7c1893a to your computer and use it in GitHub Desktop.
Save felipsimoes/8fd59af763b752c08407f12ed7c1893a 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

NaN == NaN // false

1 / 0 // Infinity
-1 / 0 // -Infinity

0 / -1 // -0

0 == -0 // true

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

typeof NaN // "number"

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

[] + [] // ""

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

{} + [] // 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.

Testado em

  • Google Chrome v53.0.2785.116
  • NodeJS v4.4.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment