Last active
August 2, 2017 04:08
-
-
Save MJ111/f2cc60cddca50a6d5cd2571d7c99fb6d to your computer and use it in GitHub Desktop.
Weird JavaScript Snippet
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
// 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 |
"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
Omg... Welcome to the Alice's JavaScript Wonderland!