You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Variables store data. Data types describe the kind of data. Operators let you manipulate that data. Mastering these three concepts is essential before writing any meaningful JavaScript program.
JavaScript provides three keywords for declaring variables:
| Keyword | Scope | Reassignable? | Hoisted? | Best For |
|---|---|---|---|---|
var | Function | Yes | Yes (initialised as undefined) | Legacy code — avoid in modern JS |
let | Block | Yes | Yes (but not initialised — "temporal dead zone") | Values that change |
const | Block | No | Yes (but not initialised) | Values that stay the same |
var oldWay = "I'm function-scoped"; // avoid in modern code
let counter = 0; // can be reassigned
const PI = 3.14159; // cannot be reassigned
Rule of thumb: Default to
const. Useletonly when you need to reassign. Never usevarin new code.
JavaScript has eight data types, split into primitives and objects.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.