Comp 110 Primitive Data Types

Simple Data Types

There are three simple data types:

 number, string, boolean

These data types are known as primitives. These store single pieces of data and are the building blocks of everything we will create in code. Primitive data types can be combined together to construct more complicated compound data types. On this page we'll give an overview of each primitive type.

number

The number type is used for numerical data, which includes positive, negative, decimal and whole numbers.

Examples of number literals:

110
-123.45

string

The string type is used for textual data. All strings are enclosed in double quotes. Anything inside of these quotes is part of the string.

Examples of string literals:

"hello"
"COMP110"
"110"
"*Go heels!*"

Note: "110" is treated as a string since it's in double quotes. This is NOT the same as the number 110.

boolean

The boolean type is used for true and false. A boolean can be either true or false - that's all folks!

Examples of boolean literals:

true
false

More examples:

print("UNC"); // "UNC" is a string literal. This prints UNC
print(2018); // 2018 is a number. This prints 2018
print(true); // true is a boolean. This prints true
print("true"); // "true" is a string since it is in double quotes. This prints true
print("1789"); // "1789" is a string since it's in double quotes. This prints 1789