Different numbers for friends



When I console.log(friends), the numbers I get are not what I included. I understand why Bill's number is different, as the number does not include the zero. That is OK. But can someone explain the logic as to why Steve's number is so drastically different? Thanks.

var friends = new Object();
friends.bill = {};
friends.steve = new Object();

// adding bill's info
friends.bill.firstName = "Bill";
friends.bill.lastName = "Bobby";
friends.bill.number = 02125768;
// adding steve's info
friends.steve.firstName = "Steve";
friends.steve.lastName = "Stank";
friends.steve.number = 02125764;


I think, because number starts with 0,JavaScript treats it as number in octal system.
The number you getting there is 568308, decimal representation of 02125764 .

as first number have 8 (bill's, octal system: 0, 1, 2, 3, 4, 5, 6, 7) in it so Js represents it as decimal system number.

To deal with this, You can make the phone numbers string type.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.