Course Lessons
Lesson 1 of 3
Variables and Data Types
Learn how to store and work with different types of data in JavaScript using variables.
16 minutes
Variables and Data Types
Variables are containers for storing data values in JavaScript.
Declaring Variables
JavaScript has three ways to declare variables:
- let: Block-scoped, can be reassigned
- const: Block-scoped, cannot be reassigned
- var: Function-scoped (older syntax)
Data Types
Primitive Types
- String: Text data (
"Hello World") - Number: Numeric values (
42,3.14) - Boolean: True or false values
- Undefined: Variable declared but not assigned
- Null: Intentional absence of value
Best Practice
Always use const by default, and only use let when you need to reassign the variable.
Code Example
// Using const for values that won't change
const name = "Elena";
const age = 28;
const isStudent = false;
// Using let for values that will change
let score = 0;
score = score + 10;
console.log(`${name} is ${age} years old`);
console.log(`Current score: ${score}`);