Data types are used to optimize the data that a variable can contain. Understanding primitive data types is a basic building block of when learning JavaScript
- Primitives
- Objects
There are five primitive types:
- string
- Example: "hello there!", 'hello there'
- number
- Example: 1, 200, 3.14159
- boolean
- Example: true, false
- Booleans are used in control structures like conditional statements
- undefined
- Example: undefined is the default value for any variable that has been declared but has not been assigned a value
- null
- null is a representation of the intentional absence of any object value. Often used to indicate that a variable should hold a value and doesn't
- Create a new project directory with an index.html and main.js file
- Link your main.js file with your index.html file by adding <script src="main.js"></script> just before the /body tag in the index.html file
- Create and assign a variable for all JavaScript data types in the main.js file
- You should console.log the typeof each variable like the example below
let x = 'Sally Smith'; console.log(typeof x);
- Mutate each variable and console.log typeof each
- Perform mathematical operations using mixed data types and console.log typeof each