+ 1

why output of 3.5 +020 is 19.5 in JavaScript?

15th Nov 2019, 1:57 PM
Bashir Uddin
Bashir Uddin - avatar
2 Answers
+ 6
Hello Al Sirang The octal numbers are represented by adding a 0 as prefix to them.. Just like we use 0x as prefix for hexadecimal. 020 is octal equivalent of 16 You can find this value by repeated division by base 8 method or Try toString method and get octal value of decimal 16 alert((16).toString(8)) Result of this will be 20 I hope you are clear why 3.5+16 =19.5 :) happy learning refer : https://en.m.wikipedia.org/wiki/Octal#In_computers
15th Nov 2019, 2:03 PM
🇼🇳Omkar🕉
🇼🇳Omkar🕉 - avatar
+ 3
decimal literals can start with a zero (0) followed by another decimal digit, but if every digit after the leading 0 is smaller than 8, the number gets parsed as an octal number. so: "020" parsed as octal in non-strict mode (16 in decimal)
15th Nov 2019, 2:07 PM
MO ELomari
MO ELomari - avatar