Data types

2 snippets across 2 stacks — JavaScript, SQL

JSJavaScript

Primitive Types

JS · Data Types
syntax
string | number | boolean | undefined | null | symbol | bigint
example
const name = "Mira";       // string
const age = 28;            // number
const active = true;       // boolean
const missing = undefined; // undefined
const empty = null;        // null
const id = Symbol("id");   // symbol
const big = 900719925474099267n; // bigint

Note Primitives are immutable and compared by value. There are 7 primitive types in total.

SQLSQL

Common Data Types

SQL · Table Operations
syntax
INTEGER, BIGINT, SMALLINT
DECIMAL(precision, scale), NUMERIC
VARCHAR(n), TEXT, CHAR(n)
BOOLEAN
DATE, TIME, TIMESTAMP, TIMESTAMPTZ
UUID, JSON, JSONB
example
CREATE TABLE products (
  id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  product_name VARCHAR(200) NOT NULL,
  price DECIMAL(10, 2) NOT NULL,
  weight_kg NUMERIC(6, 3),
  description TEXT,
  is_available BOOLEAN DEFAULT true,
  metadata JSONB,
  created_at TIMESTAMPTZ DEFAULT NOW()
);
output
-- Demonstrates typical column type choices

Note Use DECIMAL for money — never FLOAT or DOUBLE, which have rounding errors. Use TEXT over VARCHAR when you do not need a length limit. JSONB (PostgreSQL) is preferred over JSON because it supports indexing.