JavaScript Data Types

Quick Guide to Primitives and Objects

itsjmendez
2 min readMay 16, 2024

Primitive Data Types πŸͺ¨

JavaScript offers a set of fundamental data types, known as primitive types, that represent basic data values. These include:

Number πŸ”’

Represents both integers and floating-point numbers. Examples: 42, 3.14, -0.5. Special values include Infinity, -Infinity, and NaN (Not-a-Number).

String πŸ”€

Used for text. Strings can be enclosed in single quotes, double quotes, or backticks. Examples: 'hello', "world", `Hello, ${name}!`.

Boolean πŸ”¦

Represents logical values: true or false. Example: let isActive = true;.

Undefined ✨

A declared variable without an assigned value. Example: let x; // x is undefined.

Null πŸ•³οΈ

Represents the intentional absence of any value. Example: let y = null;.

Symbol πŸ”£

Unique and immutable values are often used as object keys. Example: let sym = Symbol('description');.

BigInt β˜€οΈ

For integers beyond the safe integer range of Number type. Example: let bigInt = 1234567890123456789012345678901234567890n;.

Non-Primitive Data Types (Objects) πŸ”₯

While primitive types handle basic data, JavaScript also provides more complex data structures to organize information:

Object 🍎

Stores collections of data and more complex entities. Example: let person = { name: 'John', age: 30 };.

Array πŸŽοΈπŸš™πŸš“πŸš—

An ordered collection of values. Example: let arr = [1, 2, 3, 4];.

Function 🏭

A block of code for performing tasks. Example: function greet() { return 'Hello'; }.

Date πŸ“…

Handles dates and times. Example: let now = new Date();.

RegExp 🧬

Pattern matching within strings. Example: let regex = /ab+c/;.

Map and Set πŸ—ΊοΈ

Map holds key-value pairs; Set holds unique values. Examples: let map = new Map();, let set = new Set();.

Useful resources:

πŸš€βœ¨

x, in, ig

--

--

No responses yet