Data Types in Javascript
Introduction
JavaScript supports various data types and data structures. This guide covers all data types in JavaScript, providing examples and explanations for each.
Primitive Data Types
Primitive data types are the most basic data types in JavaScript. They include:
String
Represents textual data
Number
Represents numeric values
Bigint
Represents integers with arbitrary precision.
Boolean
Represents true or false values
Undefined
Represents an uninitialized variable
Null
Represents an intentionally absent object value.
Difference between null and undefined
You can check this article about the difference between null and undefined Null vs undefined
Symbol
Represents a unique identifier.
Reference Data Types
Reference data types are complex types that reference objects and functions. Also all of them (including date, function, array) is an object.
We have a full guide about reference data types as well the reference as a whole, it is super important topic however neglected by the developers. Reference in Javascript
Object
A collection of key-value pairs.
Array
An ordered list of values.
Function
A block of code designed to perform a particular task.
Date
Represents date and time
Special Data Types in JavaScript
JavaScript also includes special data types and structures:
Typed array
Provides a mechanism for accessing raw binary data
Map
A collection of keyed data items, like an object but with key types.
Set
A collection of unique values.
WeakMap
A collection of keyed data items where keys are weakly referenced.
WeakSet
A collection of objects that are weakly referenced.
Javascript and loosely types
JavaScript is a loosely typed language, so you can change the type of a variable after it has been declared.