📖 Notes LESSON 14 OF 32

Variables, Data Types & Operators

⏱️ 22 min
JavaScript

The Building Blocks of Every Script

Every JavaScript program starts with variables and data types. Getting const vs let right, and knowing your six core data types, prevents most beginner bugs.

const, let, and Why var Is Out

🔒
const
Cannot be reassigned — the default choice for most values.
🔓
let
Can be reassigned — use only when the value actually changes.
⚠️
var
Old style, function-scoped instead of block-scoped — avoid in modern code.
🎯
===
Strict equality — always prefer over the loose ==.

Six Core Data Types

  • number, string, boolean, array, object, undefined/null
Variables, Types & Operators
JS
// Variables
const name = "Ali";    // cannot reassign
let score = 0;         // can reassign

// Data types
const num = 42;        // number
const text = "hello";  // string
const flag = true;     // boolean
const arr = [1,2,3];   // array
const obj = {key:"v"}; // object

// Operators
console.log(10 + 3);   // 13
console.log(10 % 3);   // 1 remainder
console.log(10 ** 2);  // 100 power
⚠️
Always use === instead of ==
== converts types before comparing (so 0 == "0" is true), which causes subtle bugs; === compares value and type together, so it never silently coerces one type into another.
🗒 Cheat Sheet 📝 Worksheet