Skip to content

Type

Easy — everyone uses thisGeneral Dev

ELI5 — The Vibe Check

A type tells the computer what kind of thing a value is — is it a number, text, true/false, or a list? Types matter because you cannot add a number to a word (well, JavaScript will try anyway). Types help the computer know what operations make sense on a value.

Real Talk

A type (or data type) is a classification that specifies what kind of value a variable holds and what operations can be performed on it. Primitive types (number, string, boolean, null, undefined) hold simple values directly. Reference types (object, array, function) hold a pointer to a memory location. Languages enforce types either at compile time (static typing) or at runtime (dynamic typing).

Show Me The Code

// JavaScript types (dynamic — determined at runtime):
typeof 42;          // 'number'
typeof 'hello';     // 'string'
typeof true;        // 'boolean'
typeof null;        // 'object' (famous JS bug!)
typeof undefined;   // 'undefined'
typeof {};          // 'object'
typeof [];          // 'object' (arrays are objects in JS)
typeof function(){}; // 'function'

// TypeScript types (static — checked at compile time):
const age: number = 25;
const name: string = 'Alice';
const active: boolean = true;

When You'll Hear This

"What type does that function return?" / "Type errors at compile time are way better than at runtime."

Made with passive-aggressive love by manoga.digital. Powered by Claude.