Variables & Data Types
JS Basics
Preview
Variables
let, const, var
| Keyword | Can change? | Scope |
|---|---|---|
| const | No (can't be reassigned) | Block |
| let | Yes | Block |
| var | Yes | Function (avoid) |
Primitive types
const name = "Kofi"; // string\nconst age = 25; // number\nconst price = 19.99; // number (float)\nconst online = true; // boolean\nconst nothing = null; // null\nlet later; // undefinedChecking types
typeof "hello"; // "string"\ntypeof 42; // "number"\ntypeof true; // "boolean"Naming rules
- Use camelCase:
firstName, notfirst_name - Start with a letter,
_or$ - No spaces or reserved words
- Names should describe their meaning
Template literals
const greeting = `Hello, ${name}! You are ${age}.`;Tip: Useconstby default and only switch toletwhen you must reassign. This prevents accidental bugs.
This is a free preview lesson
Enroll in the JavaScript Fundamentals to unlock every lesson, lesson PDF guides, quizzes and your certificate - and start creating your own pieces today.