Skip to content

Instantly share code, notes, and snippets.

@scriptschat
Created Sep 24, 2020
Embed
What would you like to do?
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