Print

Javascript Hints And Tips

issues with parseInt default:


when using parseInt, be aware that if you have a leading 0, parseInt will interpret the number by default as an Octal number.. i.e 00 - 07. This means that 08 and 09 are invalid numbers and will return a result of 0.

e.g:

var myTestString = '08';
 
// This will set myOctalReturnInt to 0, which is incorrect.
var myOctalReturnInt = parseInt(myTestString);
 
// This will set it properly to 8 as a number.
var myReturnInt = parseInt(myTestString, 10);






Created by: jeff. Last Modification: Thursday 04 of August, 2011 12:49:13 CST by admin.