01. Variables & Data Types
Explanation
JavaScript variables are the building blocks of any application, serving as containers for data values.
Using `const` is the modern standard for variables that should not be reassigned, providing safety and readability.
On the other hand, `let` is used for variables that will change over time, such as counters or mathematical accumulators.
Data types like Strings, Numbers, and Booleans define what kind of data the variable stores and how it can be used.
Understanding the difference between declaration, initialization, and assignment is crucial for avoiding bugs.
Always prefer `const` by default and only switch to `let` when you specifically need to change the value later.
Example
const name = 'Dev'; let count = 0;
Exercise Task
Declare a constant 'username' with your name and a let variable 'score' initialized to 0. Log both.
script.js
1
2
// Declare variables here
Console
Click "Run" to execute your code...