Variables Types
In JavaScript, there are different types of things we can store in a variable.
One type is called a number
, which is like counting how many toys you have.
Another type is called a string
, which is like writing your name.
And then there's a type called boolean
, which is like saying whether something is true or false.
It's important to know what type of thing you're storing in a variable because you can do different things with each type. For example:
- you can make calculations with numbers
- you can create a sentence with your name using a string
- you can check if something is true or false using a boolean
There are other types of data in JavaScript, but we'll learn about those later.
To declare a number, you can just write the number:
To declare a string, you need to put quotes around it:
Notice that the quotes don't matter, as long as you use the same type of quotes on both sides.
To declare a boolean, you can just write true
or false
:
In the code below we have 3 variables declared. Define a value for each variable following the following types:
myName
(string)
myAge
(number)
isOpen
(boolean)
The variable value is not important, just the type.