I tried to add two numbers in Javascript:
var output;
output = parseInt(a)+parseInt(b);
alert(output);
It gives wrong output value, e.g. if a = 015, and b = 05. Why is this so?
Expected result of above example should be 20.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you prefix your numbers with
0, you’re specifying them in base 8.015is therefore 13, and the sum is 18.Use the second
parseIntargument to force a base: