Understanding the different types of data that can be used in JavaScript is essential for building reliable and efficient programs. In this blog post/quick lecture notes, we'll briefly explore the different types of JavaScript data types.
Primitive
Primitives are data types that do not have named attributes. They do not have methods or properties either.
The Seven Primitive Data Types are:
String - representation of a sequence of characters enclosed in single (') or double (") quotes
let str = "abc"
Number - numeric values that are integers or floating-point numbers
let num = 5
BigInt - whole number larger than the maximum safe number a Number variable or data type can have
let bigInteger = Number.MAX_SAFE_INTEGER
Boolean - true or false value that represents a logical entity
let bool = true
Undefined - variable that has not been assigned a value
let undefinedValue
Symbol - unique identifier (rarely used from what I gathered from the lecture)
let sym = Symbol()
Null - represents a value that does not exist or is invalid
Structured
Structured means that it has one or more named attributes. It can have methods or properties, unlike primitive data types.
- Objects - a collection of key-value pairs which can also be called map, dictionary, or hash-table in other languages. Arrays are considered an object.
let oj { id: 1, name: cat}
Fun fact: Functions are also considered an Object type! See 4.3.31 in ECMA International for terms and definitions.
There might be more examples of structured data types compared to what I went over. However, this is just the beginning! I am super excited to learn more about JavaScript.
Top comments (0)