DEV Community

Phuong-Cat Ngo
Phuong-Cat Ngo

Posted on • Updated on

JavaScript Data Types

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:

  1. String - representation of a sequence of characters enclosed in single (') or double (") quotes
    let str = "abc"

  2. Number - numeric values that are integers or floating-point numbers
    let num = 5

  3. BigInt - whole number larger than the maximum safe number a Number variable or data type can have
    let bigInteger = Number.MAX_SAFE_INTEGER

  4. Boolean - true or false value that represents a logical entity
    let bool = true

  5. Undefined - variable that has not been assigned a value
    let undefinedValue

  6. Symbol - unique identifier (rarely used from what I gathered from the lecture)
    let sym = Symbol()

  7. Null - represents a value that does not exist or is invalid

Source

Structured

Structured means that it has one or more named attributes. It can have methods or properties, unlike primitive data types.

  1. 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)