JavaScript AcademyProfessional Engineering

Learning object 7 of 100

Equality comparison laboratory

Enter two values and compare them with ===, ==, Object.is, !==, < and >, with the type of each side shown.

Loading…

What it shows

=== is true only when type and value match. == converts types first, which is why 0 == "" is true. Object.is is like === except that it treats NaN as equal to itself and separates 0 from -0. Arrays and objects are compared by reference, so two arrays with the same contents are not equal.

Guided experiment

  1. Compare "5" and 5. Which operators disagree?
  2. Compare NaN with NaN. Which operator says true?
  3. Compare "10" and "9" with <. Why is the text result different from the numbers 10 and 9?

Predict

What is null == undefined?

Related

Lessons: Lesson 11: Comparison operators

Projects: Project 9: Shopping Cart Price Calculator

Source: web/assets/js/objects/object-007.js in the companion repository.