JavaScript Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.00

Numeric Value Literals

This section provides descriptions on numeric value literals and a tutorial example on how to use them in JavaScript source code.

To provide values of numbers in JavaScript source code, you need to use numeric value literals in 3 formats:

1. Integer Literal - A sequence of digits following an optional sign character to represent an integer value between -9007199254740992 (-2**53) and 9007199254740992 (2**53) inclusive. For example: 2008, -12, etc.

2. Hexadecimal Literal - A sequence of hexadecimal digits following 0x or 0X representing a positive integer or floating point value. A hexadecimal literal may also have a sign character. For example: 0x07D8 (2008), -0x0C (-12), 0xffffffffffffffffffff (1.2089258196146292e+24), etc.

3. Floating Point Literal - The scientific notation of a real number with the following syntax: (sign)(digits).(digits)e(sign)(digits). For example: 4.13, 0.333333, -1.51e10, 4.10e-29, etc.

In JavaScript, all numbers, including integers, are stored in 64-bit floating point format as described in the IEEE 754 standard.

Here is a JavaScript tutorial example that shows you how to use different types of number literals in JavaScript source code:

<html>
<!-- Number_Literials.html
   Copyright (c) 2008 by Dr. Herong Yang, http://www.herongyang.com/
-->
<head><title>Number Literals</title></head>
<body>
<pre>
<script type="text/javascript">
   document.write(2008);
   document.write('\n');

   document.write(0x07D8);
   document.write('\n');

   document.write(-0x0C);
   document.write('\n');

   document.write(0xffffffffffffffffffff);
   document.write('\n');

   document.write(-1.51e10);
   document.write('\n');

   document.write(4.10e-29);
   document.write('\n');
</script>
</pre>
</body>
</html>

The output of this sample JavaScript is:

2008
2008
-12
1.2089258196146292e+24
-15100000000
4.1e-29

Sections in This Chapter

Primitive Data Types - Numbers, Strings, and Booleans

Numeric Value Literals

String Literials

Declaring Variables - "var" Statements

Operators and Expressions

Operators and Expressions - Examples

Dr. Herong Yang, updated in 2008
Numeric Value Literals