Representing data with values
Primitive Data Types
- Primitive Data Types
- Number Type
- String Type
- Boolean data type
- Undefined and null
- What are statements?
- Expression Statements
- Compound and Empty Statements
- Declaration Statements
- Conditional statements
- Loop statements
- Jump Statements
Naming a Value with an Identifier
So far, as the literals we have created thus far are anonymous, we have no way to query or manipulate their values later. To fix this, we need to name them with an identifier. Doing so creates a variable, which of course is a named value.
iceCream contains undefined, a literal conveying no value.
Let’s put the string literal “Chocolate Fudge Brownie” in iceCream with the = operator:
var iceCream; iceCream = "Chocolate Fudge Brownie";
To query the value contained by a variable, type its identifier. Type iceCream, and click Run.
var iceCream; iceCream = "Chocolate Fudge Brownie"; iceCream; // "Chocolate Fudge Brownie"
To put a new value in iceCream, do another = operation. So, let’s replace “Chocolate Fudge Brownie” with “New York Super Fudge Chunk” like so:
var iceCream; iceCream = "Chocolate Fudge Brownie"; iceCream = "New York Super Fudge Chunk"; iceCream; // "New York Super Fudge Chunk"
Rules for naming variables
Variables are Case Sensitive
var case_matters = 'lower'; var Case_Matters = 'upper'; case_matters; // "lower" Case_Matters; // "upper"