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?
In Javascript, like other languages, starting a number with 0 would indicate it’s base 8 (Octal).
Thus,
02034in base 8 = 1052 in base 10 (decimal).