How it works...

From the implementation of the set method, we can see where the types of the arguments are being checked. Symbol, as a type, doesn't have a constructor, so we can't use the instanceof operator, but the typeof operator returns a symbol string we can check against. The Rocket instances behave like other instances we've seen in other recipes, and can be checked like the others.

When the incorrect type is passed as an argument to set, one of the conditionals will trigger and an error will be thrown.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.