using parseInt function with 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
function parseIntTest() { | |
var a = parseInt("5"); | |
console.log(`a: ${a}`) | |
//variable a will have numeric value 5 | |
// this is a bug in some of the older browsers where | |
// parseInt with '08' will return 0 | |
// if you are supporting older browsers, make sure you | |
// mention second argument, the base for number system as 10 | |
var b = parseInt("08"); | |
console.log(`b: ${b}`) | |
//variable b will have numeric value 0 | |
var c = parseInt("08", 10); | |
console.log(`c: ${c}`) | |
//variable c will have numeric value 8 | |
} | |
parseIntTest(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment