HTML and CSS Reference
In-Depth Information
Figure 3.3 Output from Example 3.4.
3.1.2 Composite Data Types
We mentioned that there are two types of data: primitive and composite. This chapter
focuses on the primitive types: numbers, strings, and Booleans—each storing a single
value. Composite data types, also called complex types, consist of more than one compo-
nent. Objects, arrays, and functions, covered later in this topic, all contain a collection of
components. Objects contain properties and methods, arrays contain a sequential list of
elements, and functions contain a collection of statements. The composite types are dis-
cussed in later chapters.
3.2 Variables
Variables are fundamental to all programming languages. They are data items that rep-
resent a memory storage location in the computer. Variables are containers that hold
data such as numbers and strings. Variables have a name , a type , and a value .
num = 5; // name is "num", value is 5, type is numeric
friend = "Peter"; // name is "friend", value is "Peter",
// type is string
The values assigned to variables can change throughout the run of a program whereas
constants, also called literals, remain fixed. JavaScript variables can be assigned three
types of data:
numeric
string
Boolean
Computer programming languages like C++ and Java require that you specify the
type of data you are going to store in a variable when you declare it. For example, if you
are going to assign an integer to a variable, you would have to say something like:
int n = 5;
 
 
 
Search WWH ::




Custom Search