Console.log output in javascript

后端 未结 6 539
闹比i
闹比i 2021-01-01 01:22

Why do console.log(00); and console.log(01); print 0 & 1 in the browser console and not 00 & 01?

console.log(00); // prints         


        
6条回答
  •  囚心锁ツ
    2021-01-01 01:44

    I did some research on it and found this solution.

    Point 1 - If any number leading with zero will not always be considered as the decimal.

    point 2 - A number leading with zero and do not contain 8 or 9 in remaining number will be considered as octal and converted to decimal when printing its value.

    point 3 - A number leading with zero and contains 8 or 9 in remaining number will be considered as decimal value.

    point 4 - 00 to 07 will not be converted to decimal as they are already in decimal.

    var a = 07
    console.log(a)  //// 7
    
    var a = 08
    console.log(a)  //// 8
    
    var a = 016
    console.log(a) //////14
    
    var a = 018
    console.log(a) //////18
    
    var a = 078
    console.log(a) //////78
    
    var a = 077
    console.log(a)  ////////63
    
    var a = 096
    console.log(a) /////96
    

提交回复
热议问题