Could anyone explain why the result is 5?
console.log(parseInt('101', 2)); // 5
Could anyone explain why the result is 5?
console.log(parseInt('101', 2)); // 5
The second argument you are passing to parseInt function is called Radix.
When you are passing 2 means that the string is in binary so the binary of 5 is 101.
5 (Decimal) = 101 (Binary)
That is why you are getting 5 as int.