Last active
January 10, 2018 11:15
-
-
Save aozora/12341bc519e5eb9a55ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// In this function we’re incrementing the count | |
// property on the object that was passed in | |
// but there's a bug.. | |
function incrementCount(counter) { | |
if (counter.count) { | |
counter.count++; | |
} else { | |
var counter = 1; | |
counter.count = counter; | |
} | |
} | |
// What happens when we call it in these 3 ways? comment each one. | |
incrementCount(0); | |
incrementCount({ | |
count: 10 | |
}); | |
incrementCount(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The 3rd give this error: Uncaught TypeError: Cannot read property 'count' of undefined
The first 2 do nothing, since there's no "return" in the function.