Inheritance, Composition and JavaScript's Types

Stephen Gruppetta 20 Lessons 6h 27m Updated intermediate js

The Elm Street toy library runs from a garage, and its volunteers track the toys with a few Node scripts in the terminal. There’s a wooden train set, a 1,000-brick building set, and a dress-up box, and children like Maya Chen and Leo Okonkwo borrow them.

All toys are lent alike, but a building set counts its bricks and a dress-up box has a size. A lending desk isn’t a toy at all. When a loan fails, the script has to tell a refused loan from a real bug.

And an age a volunteer types arrives as text, so "3" + 1 gives "31". Behind all of this sits one question: when is one thing a kind of another, and when is it built from parts? You’ll learn how to:

  • Design a small family of classes
  • Choose composition where inheritance doesn’t fit
  • Define custom errors
  • Convert values explicitly where they enter a program
  • Build a program from a brief, then plan one of your own

The first two sections mix text lessons with a short video that looks behind the scenes, at a method lookup walking up the prototype chain and at a loan that changes both sides at once. Every section ends with an exercise you write in the browser, where automated tests check your code. You’ll run the lesson examples in your own terminal, in a small Node project.

In the project, a family donates board games, puzzles, and ride-on toys, and you build the tracker from a brief and a check script, without a walkthrough. Each kind extends an Item base class with its own rule: a puzzle records missing pieces, and a ride-on has an age range.

Lending is composed in, and the desk throws a LoanError for an item that’s already out or a borrower who’s too young, changing nothing. Ages and quantities typed at the terminal become numbers where they arrive.

Two graded exercises check the catalog and the lending. Then you explain your tracker to the AI mentor and make a change the brief didn’t ask for. After that, you plan a program of your own, review it with the mentor, and take a quiz.

This is the last course on the Intermediate JavaScript path. It’s for programmers who have finished JavaScript Basics and can write classes with private fields, getters, and setters, split a program into modules, and throw and catch errors, each recapped where it’s used. You’ll need a current Node LTS, a terminal, and any editor.

What’s Included:

  • 20 Lessons
  • Video Subtitles and Full Transcripts
  • Translated Subtitles in 8 Languages
  • 2 Downloadable Resources
  • Interactive Quiz to Check Your Progress
  • 6 Hands-On Coding Exercises
  • Q&A With JavaScript Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

Related Learning Paths:

About Stephen Gruppetta

Stephen obtained a PhD in physics and worked as a physicist in academia for over a decade before becoming a programming educator. He's constantly looking for simple ways to explain complex things.

» More about Stephen

Each tutorial at RealJS is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

← Browse All Courses