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.

Frequently asked questions

How does JavaScript handle data types?
This task is covered in 2 stacks on this page: JavaScript, SQL. The "Primitive Types" snippet in JavaScript uses `string | number | boolean | undefined | null | symbol | bigint`.
Which code does the JavaScript example use?
The "Primitive Types" snippet uses `string | number | boolean | undefined | null | symbol | bigint`, from the Data Types section of the JavaScript cheat sheet.
Which stacks cover "data types" on this page?
JavaScript, SQL. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Primitive Types": Primitives are immutable and compared by value. There are 7 primitive types in total.