Checking an Object's Class With instanceof

The port’s place check now survives orchard’s null location. The next line of readings_check.py asks whether the reading’s time is really a time. School’s clock isn’t set, so its reading arrives with the text "not set", and the Python script rejects it.

typeof can’t make that call because a date, an array, and a plain object are all "object" to it. JavaScript has a separate operator for asking about an object’s class.

Ask Whether an Object Belongs to a Class

In Python, isinstance() tells a datetime apart from a dictionary like the location:

Language: Python
from datetime import datetime

taken_at = datetime(2026, 11, 4, 9, 0)
location = {"lat": 54.61, "lon": -3.05}
print(isinstance(taken_at, datetime), isinstance(location, datetime))

That prints True False. In the port, new Date("2026-11-04T09:00") creates ridge’s time, interpreted as local time. That’s all you need to know about dates for this lesson. Here’s the code, with typeof alongside and an array for comparison:

Language: JavaScript
const takenAt = new Date("2026-11-04T09:00");
const location = { lat: 54.61, lon: -3.05 };
const stations = ["ridge", "mill", "orchard", "school"];
console.log(typeof takenAt, typeof location, typeof stations);
console.log(takenAt instanceof Date, location instanceof Date);
console.log(stations instanceof Array, stations instanceof Object);

Run it, and typeof identifies all three as objects, while instanceof tells the time from the location:

Language: Program Output
object object object
true false
true true

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.