Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript returning strange value

Tags:

javascript

I was testing a function out to see what happens when it's parameters are null and decided to put an else statement with it. To my surprise, it did not log the parameters that I have passed, it's logging something else entirely. Maybe someone can shed some light on this, here's the code:

function testing(o) {
    if (!o) {
        return "Sorry, looks like you need to pass an argument.."
    } else {
        return o;
    }
}

console.log(testing(02034));
//logs 1052

What's going on here?

like image 412
Sethen Avatar asked Dec 06 '25 19:12

Sethen


1 Answers

In Javascript, like other languages, starting a number with 0 would indicate it's base 8 (Octal).

Thus, 02034 in base 8 = 1052 in base 10 (decimal).

like image 123
Jay Avatar answered Dec 08 '25 08:12

Jay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!