> For the complete documentation index, see [llms.txt](https://program.hackyourfuture.dk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://program.hackyourfuture.dk/course-content/backend/advanced-javascript/week4.md).

# Week 4

Over the past three weeks you've transformed data with array methods, managed async flows with callbacks and Promises, and fetched from a real API. But all your data has been plain objects - no validation, no built-in behavior, no structure beyond what you remember to add each time.

This week you'll learn classes: blueprints for creating objects with consistent structure and built-in behavior. You'll build Tea, Order, and Inventory classes that validate data, calculate totals, and work together - just like the models behind the Tea Shop API you've been using.

## Contents

* [Preparation](https://program.hackyourfuture.dk/course-content/backend/advanced-javascript/week4/preparation.md)
* [Slides](https://github.com/HackYourFuture-CPH/program/tree/main/courses/backend/advanced-javascript/week4/session-materials/slides/index.html)
* [Session Plan](https://program.hackyourfuture.dk/course-content/backend/advanced-javascript/week4/session-plan.md) (for mentors)
* [Session Materials](https://github.com/HackYourFuture-CPH/program/tree/main/courses/backend/advanced-javascript/week4/session-materials/README.md)
* [Assignment](https://program.hackyourfuture.dk/course-content/backend/advanced-javascript/week4/assignment.md)

## Learning Goals

By the end of this session, you will be able to:

* [ ] Understand why classes exist (organizing data with behavior)
* [ ] Declare a class using `class`, `constructor`, and `this`
* [ ] Instantiate objects from classes using `new`
* [ ] Add methods to classes and call them on instances
* [ ] Use `this` to access and modify instance state
* [ ] Use static methods for utility operations on a class
* [ ] Use inheritance with `extends` and `super()`
* [ ] Understand the difference between a class (blueprint) and an object (instance)

### After this session you will understand code like this

```js
// From scattered plain objects...
const tea = { name: "Sencha", pricePerGram: 0.12, origin: "Japan" };
// No validation, no behavior, no consistency

// ...to structured classes with built-in behavior
class Tea {
  constructor(name, pricePerGram, origin) {
    this.name = name;
    this.pricePerGram = pricePerGram;
    this.origin = origin;
  }

  priceFor(grams) {
    return this.pricePerGram * grams;
  }
}

const sencha = new Tea("Sencha", 0.12, "Japan");
console.log(sencha.priceFor(100)); // 12
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://program.hackyourfuture.dk/course-content/backend/advanced-javascript/week4.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
