Course JavaScript Fundamentals

Variables & Data Types

JS Basics Preview

Variables

let, const, var

KeywordCan change?Scope
constNo (can't be reassigned)Block
letYesBlock
varYesFunction (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;               // undefined

Checking types

typeof "hello";   // "string"\ntypeof 42;        // "number"\ntypeof true;      // "boolean"

Naming rules

  • Use camelCase: firstName, not first_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: Use const by default and only switch to let when 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.


Discussion