Skip to content

Instantly share code, notes, and snippets.

@MJ111
Last active August 2, 2017 04:08
Show Gist options
  • Save MJ111/f2cc60cddca50a6d5cd2571d7c99fb6d to your computer and use it in GitHub Desktop.
Save MJ111/f2cc60cddca50a6d5cd2571d7c99fb6d to your computer and use it in GitHub Desktop.
Weird JavaScript Snippet
// 1.
'0' == 0 // true
0 == [] // true
'0' == [] // false
// 2.
['10', '10', '10'].map(parseInt) // [10, NaN, 2]
// 3.
let obj = {bar:0}
for (obj.bar of [1,2]) {}
console.log(obj.bar) // 2
// 4. run two lines at once.
(function () { console.log('hi') })()
[1,2].slice() // TypeError: Cannot read property '2' of undefined
// 5. parseInt
parseInt('null', 10) // NaN
parseInt('null', 23) // NaN
parseInt('null', 24) // 23
@jkim848
Copy link

jkim848 commented Jun 29, 2017

Omg... Welcome to the Alice's JavaScript Wonderland!

@jkim848
Copy link

jkim848 commented Jun 29, 2017

"My mom always said life was like a box of JavaScript. You never know what you're gonna get." - by Forest Gump

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