Values
- Values are the “things” we compute with. At the basic level computers operate on fairly simple values, mostly numbers. Everything else is built up from there. When you watch a video on your computer, it is translating billions of numbers into pixels on your screen to make the picture and signals to your speakers to make the sound.
Types of values
- Every value has a type that determines what we can do with the value.
- In this course we will learn about three basic types of values: numbers, booleans (logical values), and strings (text). Later on we’ll learn about how to build more complex kinds of values out of these basic kinds.
Numbers
- Numbers are used in programming for all the kinds of things we use them for outside of programming: counting, representing measurements, etc. They are also used to express things like where on a screen to draw something (in terms of coordinates). And many other things.
- Numbers in Javascript are written more or less the way you’re used to:
1
, 2
, 3.5
, -9
.
- There are limitations to numbers in computers: just like we can’t represent 1/3 exactly in decimal (without a repeating decimal) there are numbers that can’t be represented exactly in a computer (including 1/3 but also 1/5 and 1/10.)
Booleans
- Boolean values are the basic building blocks of logic in our programs.
- Booleans have only two values
true
and false
.
Strings
- Strings are used to represent text.
- Javascript strings are written in quotation marks. Either double quotes:
"
or single quotes '
. For example "Berkeley High"
is a string containing the name of our school. That could also be written 'Berkeley High'
.