Skip to content

Instantly share code, notes, and snippets.

@scriptschat
Created September 24, 2020 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptschat/db43b61f857c6224210226e6eadfa85b to your computer and use it in GitHub Desktop.
Save scriptschat/db43b61f857c6224210226e6eadfa85b to your computer and use it in GitHub Desktop.
using parseInt function with JavaScript
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