Checking an Object's Class With instanceof

The port’s place check now survives orchard’s null location. Next, readings_check.py rejects a reading whose taken_at isn’t a datetime, such as school’s "not set". typeof can’t make that call, because a date, an array, and a plain object are all "object" to it.

Ask Whether an Object Belongs to a Class

For objects, JavaScript’s counterpart to isinstance() is instanceof. Here new Date("2026-11-04T09:00") creates ridge’s timestamp, 09:00 local time, which is all you need to know about dates for now:

Language: JavaScript
const takenAt = new Date("2026-11-04T09:00");
const location = { lat: 54.61, lon: -3.05 };
console.log(typeof takenAt, typeof location);
console.log(takenAt instanceof Date, location instanceof Date);

typeof can’t tell them apart, but instanceof can:

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.