Octal Integer

For an octal literal, the first digit must be a zero (0). The octal literal can have numbers from 0 to 7.

 
<!DOCTYPE html>
<html>
<head>
    <title>Octal Number Example</title>
    <script type="text/javascript">
          
       var octalNum = 053; 
              
       document.writeln(octalNum);//octal for 43 
    </script>

</head>
<body>
  
</body>
</html>
  
Click to view the demo

If a number out of 0 to 7 is used, then the leading zero is ignored and the number is considered as a decimal.

 
<!DOCTYPE html>
<html>
<head>
    <title>Octal Number Example</title>
    <script type="text/javascript">
          
       var octalNum = 079; //invalid octal
              
       document.writeln(octalNum); //79
    </script>

</head>
<body>
  
</body>
</html>
  
Click to view the demo

Octal literals are invalid in strict mode.

The octal numbers are converted to decimal numbers in all arithmetic operations.

 
<!DOCTYPE html>
<html>
<head>
    <title>Octal Number Example</title>
    <script type="text/javascript">
          
       var octalNum = 056; 

       document.writeln(octalNum); //46
       
       var aNum = 123; 
       
       document.writeln(octalNum + aNum); //169
    </script>

</head>
<body>
  
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Language Basics  

Data Types:
  1. JavaScript Data Types
  2. typeof Operator
  3. The Undefined Type
  4. null Type
  5. null vs undefined
  6. Boolean Type
  7. Boolean() casting function
  8. The Literials of Number Type
  9. Octal Integer
  10. Hexadecimal
  11. Floating-Point Values
  12. Value range
  13. NaN
  14. Number Conversions:Number(), parseInt() and parseFloat()
  15. Number() function
  16. parseInt()
  17. parseFloat()
  18. The String Type
  19. String Literals and Escapes
  20. Get the String Length
  21. Converting to a String with toString() method
  22. Convert Number to String with radix
  23. Convert to String with String() casting function