Last active
June 6, 2019 17:48
-
-
Save skoshy/a3c31e327270b9d3de93ccfe8e051533 to your computer and use it in GitHub Desktop.
Different ways of parsing an integer in JavaScript
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
Input | parseInt(i) || 0 | +i || 0 | i | 0 | Notes | |
---|---|---|---|---|---|
'1' | 1 | 1 | 1 | ||
'4s' | 4 | 0 | 0 | ||
'45734584574354954345444533544354353' | 4.573458457435495e+34 | 4.573458457435495e+34 | 0 |
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
function testParse(i) { | |
return { | |
"parseInt(i) || 0": parseInt(i) || 0, | |
"+i || 0": +i || 0, | |
"i | 0": i | 0, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment