Link Search Menu Expand Document

What are Data Structures?

Data Structures are flexible and robust ways to store data. They are usually built out of several primitive types (e.g. string, number, boolean) and are grouped together in a certain way.

Arrays

Arrays are the basic collection data type in JavaScript. Arrays are lists of elements.

// const can be used for declaring array variables
// const is for data that doesn't get reassigned
const fruits = ["apple", "banana", "orange"]

Objects

Objects are a way to group variables and functions together.

const banana = {
  name: "banana",
  calories: 100,
  vitamins: ["B6", "C", "K"], // you can nest arrays in objects and vice versa
  hasPeel: true,
}