93 views

Symptoms


When using the parseInt function in a script and pass in either '09' or '08' it returns NaN instead of the expected number. 

Release


Kingston

Cause 


This is not an issue with Service Now and is the expected behavior of that function with the version of Javascript we use. The function has been updated to not work this way in the newer versions of Javascript, but using the radix will not affect the script if we update to later version. It is always recommended to have a radix per the Javascript Docs. 

Resolution 


You will need to specify the radix which is a second param for the parseInt method when there is a possibility of it starting with a leading 0. 

Additional Information 


This stack overflow question and its answers may help explain more. 
https://stackoverflow.com/questions/8763396/javascript-parseint-with-leading-zeros 

You can read more about parseInt on MDN's docs: 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt 

Article Information

Last Updated:2018-05-25 08:22:10
Published:2018-05-24