It doesn't work with 8 and 9 because parseInt believes your number is octal (base 8) and 8 and 9 would not be valid digits in base 8.Â
A leading zero identifies a string as base 8, so parseInt('09') is not the same as parseInt('9')
Specifically,Â
parseInt ('09') is interpreted the same way as parseInt('9', 8) - in the case the base is specified as 8,
whereas parseInt('9') is treated as parseInt(9,10)
also parseInt('0xff') is the same as parseInt('ff', 16) for a hex base.
As a habit, I recommend you always include the base when working with parseInt, as in parseInt(yourString, 10), if you don't expect numbers with other bases to ever be input
Btw - here's a concise version of what you are doing, with a tester for various data types
const months = (a, b) => {
 const da = new Date(a)
 const db = new Date(b)
 return Math.abs(
  12 * (da.getFullYear() - db.getFullYear()) +
  (da.getMonth() - db.getMonth())
 )
}
// like data from a sheet
const data = [
 ['1/1/2001', '1/2/1999'],
 ['1/1/2000', '2/2/2000'],
 [new Date(2002,1,1), '11/10/1987'],
 ['7/11/1921', new Date().getTime()],
 [new Date('1 aug 1934'), new Date('17-sep-1935')]
]
console.log(data.map(f=>months(f[0],f[1])))