10 - Abstract Data Types (ADT)

In the beginning there was only boolean. How did we get to things like Strings, Arrays, and the Math object? What if we want to create our own data type that can hold interesting information and useful functions? How did they create the Math object in JavaScript?

What are we learning?

In this lesson we will:


Abstract Data Types (ADT)

Numbers and booleans are what we call a primitive data type while Arrays, Strings, or the Math object in JavaScript are way more complex - we call those Abstract.

Let's learn how to declare something more custom than a number. Take a look at this simple example of creating a variable that has a name and a boolean for on or off:

let light_switch = {

    name: "Living Room",

    state: "off",

    change_state: function() { 

        if (this.state == "on")

          this.state == "off";

        else 

          this.state == "on";

    }

};


That allows us to keep track of the name of the switch and the status of it, all in one variable, named light_switch.

Practice (classwork)

We will create our own ADT - The Stack 🥞  (GitHub)


🐿️