Skip to content

Instantly share code, notes, and snippets.

@skoshy
Last active June 6, 2019 17:48
Show Gist options
  • Save skoshy/a3c31e327270b9d3de93ccfe8e051533 to your computer and use it in GitHub Desktop.
Save skoshy/a3c31e327270b9d3de93ccfe8e051533 to your computer and use it in GitHub Desktop.
Different ways of parsing an integer in JavaScript
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
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