HTML and CSS Reference
In-Depth Information
The Building Blocks:
Data Types, Literals,
and Variables
3.1 Data Types
A program can do many things, including calculations, sorting names, preparing phone
lists, displaying images, validating forms, ad infinitum. But to do anything, the program
works with the data that is given to it. Data types specify what kind of data, such as num-
bers and characters, can be stored and manipulated within a program. JavaScript sup-
ports a number of fundamental data types. These types can be broken down into two
categories, primitive data types and composite data types.
3.1.1 Primitive Data Types
Primitive data types are the simplest building blocks of a program. They are types that
can be assigned a single literal value such as the number 5.7 , or a string of characters
such as “hello” . JavaScript supports three core or basic data types:
In addition to the three core data types, there are two other special types that consist
of a single value:
• null
• undefined
Numeric Literals. JavaScript supports both integers and floating-point numbers. Inte-
gers are whole numbers and do not contain a decimal point, such as 123 and -6. Integers
can be expressed in decimal (base 10), octal (base 8), and hexadecimal (base 16), and are
either positive or negative values. See Example 3.1.
Search WWH ::

Custom Search