A VALUE is a location in computer memory that stores DATA.
There are many kinds of values, including String, Number, Array, Date, ...
(The different kinds of values are called TYPES. Soon you will create your own types but for now, we will use the built-in ones.)
A number is what it sounds like -- any integer or decimal.
10 -12 3.14
A string is an object that's a collection of characters, like a word or a sentence.
"apple" "banana" "Cherry Pie"
A boolean is a value that is either
(It's named after George Boole, a 19th-century mathematician who invented Boolean algebra.)
Values can be combined or manipulated using operators, like...
- PLUS (
- TIMES (
- POWER (
- DOT (
An operator sends a message to the value
1 + 2sends the number
please add 2 to yourself.
Dot is a special operator that sends arbitrary messages; we will learn more about her later.
A simple expression (like a plain number or a string) evaluates to just that value.
A more complicated expression with operators keeps applying those operators until it gets down to a single value.
You can think of evaluation as asking and answering a question.
2 + 2 // Question: What is 2 + 2? 4 // Answer: 4 // Q: What is the all-caps version of the string "apple"? "apple".toUpperCase() // A: the string "APPLE" "APPLE"
We say that a statement evaluates to a value, as in "2 plus 2 evaluates to 4". You can also say "the value of 2 + 2 is 4" or "the return value of 2 + 2 is 4".
Sometimes the return value is the same as the original value.
4 * 1 // return value: 4
Sometimes the return value is a different value.
2 + 3 // return value: 5
Sometimes the return value is a different value and a different type.
"banana".length // return value: 6
Sometimes the return value is a magic value!
(5).length // return value: undefined 5 / 0 // return value: Infinity "cookie" * 10 // return value: NaN
LAB: Values: readings and exercises
- read Introduction
- read Values
- Work up to the exercise Add Two Numbers ... and feel free to continue on if you like.
- You can complete these exercises with or without a FreeCodeCamp account, but if you create one your progress will be recorded.
In these lessons, we often use comments to explain the result of executing the nearby code. In this case, we sometimes add an arrow to the comment: