JavaScript Equality and Type Checks for Pythonistas (Summary)

Congratulations, you made it to the end of the course! The Millbrook Valley Weather Co-op’s readings check now runs in JavaScript. Once you added each reading’s place and the final count, readings-check.js printed the same six lines as readings_check.py. It skips the resent ridge reading, rejects school’s, and marks orchard’s failed thermometer as unchanged.

In this course, you learned how to:

  • Compare records by the fields that identify them, such as the name "ridge #1412", because === and .includes() compare objects by identity
  • Explain why strings, numbers, and Booleans compare by value: they’re primitives, which can’t change, and their methods come from wrapper objects that JavaScript creates and throws away
  • Pair typeof with the checks it can’t make: !== null for objects, Array.isArray() for arrays, and Number.isNaN() to rule out NaN, which typeof calls a number
  • Check an object’s class with instanceof, and negate the whole test, as in !(reading.takenAt instanceof Date)
  • Read == by its rules, and replace it by checking for a missing value first, then converting and comparing with ===
  • Choose between === and Object.is() when NaN or -0 is involved

Keep the Habits That Carry Over

You ported most of the readings check line by line. Its logic stayed the same, and only the comparisons and type checks changed.

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.