Either way, there are a few easy fixes for this problem that we will cover here.
Using parseInt works because leading zeros in an integer do not create a valid integer so when you use parseInt it will remove any leading zeros because they don’t change the number in any way.
parseInt("0400", 10) // 400
In the above example, the second argument of 10 is known as the radix which is the numerical base which the parseInt method will use to parse the correct integer.
For example if you pass in 2 as the base/radix then you would be working with binary numbers, and if you use 10 you will be using the normal mathematical system that we all know and use.
The reason why you will want to pass in the radix is because it does not default to 10 like you would expect, if you want to read more about this I suggest taking a look at this post about parseInt.
Most of the time if you have a leading 0 it will be because the number is either in string format or it is from a user input.
Here is how you can do this:
+"0400" // 400
This will not work if the number is not in a string format though.
The last option would be to use a regular expression/regex to remove the first 0 in a string, but this is far from ideal because it could become confusing to write and read.
Here is how that would look:
"0400".replace(/^0+/, "") // "400"