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>
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>
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>
Home
JavaScript Book
Language Basics
JavaScript Book
Language Basics
Data Types:
- JavaScript Data Types
- typeof Operator
- The Undefined Type
- null Type
- null vs undefined
- Boolean Type
- Boolean() casting function
- The Literials of Number Type
- Octal Integer
- Hexadecimal
- Floating-Point Values
- Value range
- NaN
- Number Conversions:Number(), parseInt() and parseFloat()
- Number() function
- parseInt()
- parseFloat()
- The String Type
- String Literals and Escapes
- Get the String Length
- Converting to a String with toString() method
- Convert Number to String with radix
- Convert to String with String() casting function