Created
September 27, 2017 22:16
-
-
Save TheWass/c93fef1e39abe820a7f896e4d69f719b 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
function coerceIntWithDefault(test) { | |
test = (test !== 0) ? (test || 42) : 0; | |
return test; | |
}; | |
var test; | |
coerceIntWithDefault(test); | |
// test === 42; | |
test = 78; | |
coerceIntWithDefault(test); | |
// test === 78; | |
test = 0; | |
coerceIntWithDefault(test); | |
// test === 0; | |
test = null; | |
coerceIntWithDefault(test); | |
// test === 42; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment