JavaScript: Variables & Types

Understand let, const, and data types you'll use every day.

Declaring variables

let count = 0;
count = count + 1; // ok

const siteName = 'Intro Blog';
// siteName = 'Other' // ❌ TypeError: Assignment to constant variable.

Common types

const age = 21;                  // number
const name = 'Ahbab';            // string
const isStudent = true;          // boolean
const nothing = null;            // null
let notSet;                      // undefined
const user = { id: 1, name }     // object
const tags = ['html', 'css'];    // array (also an object)

console.log(typeof age);         // 'number'
console.log(typeof user);        // 'object'

Practice

  1. Declare a const for your name and a let for a counter; increment it.
  2. Create an object describing a course with title, hours, and tags.
  3. Log the typeof different variables.

Next up

Quick Check

Which keyword declares a block-scoped constant?