Once you read this guide you will be well on your way to understanding the 4 different data types and how to use them in Javascript!
- A String is zero or more characters written within quotations.
- Some examples of strings are:
var favoriteFlower = "Rose"
var typeOfTea = "Black"
var myDogsName = "Jasmine"
- Boolean data represents one of two values: TRUE or FALSE.
- It is typically used in combination with Boolean Logic to create if() statements in your code, such as:
var isOver21 = TRUE;
var isNotOver21 = FALSE;
if (isNotOver21) {
alert ('You may not enter this website.');
}
- Integers are whole numbers (not fractions) that can be positive, negative or zero.
- Such as:
var windchill = -25
var myAge = 30
- Floats are numbers that contain decimal points.
- Such as:
var savingsRate = 0.01
var exactTemp = 98.6
- Arrays represent collections of data. They allow you to store multiple values in a single variable.
- Some examples of arrays:
var fruits = ["Banana", "Apple", "Cherry"]
var numbers = [4, 6, 21, 43, 25, 28]
var latteIngredients = ["Espresso", "Milk", "Foam", "Sugar"]