Scaffold students to evaluating and understanding 3 === “3” in Javascript using the following steps to help students learn the difference between confusing comparison operators.

  • The two comparison operators for equality in Javascript, == and ===, create a lot of confusion for students.
    • Tackling triple equals, ===, is especially tricky for intro students because triple equals checks for equal value and for equal type.
  • Activity:
    • Draw 3 == "Three" on the board.
      • Ask students, does 3 == "Three"
      • Follow up by asking students, "Why?"
        • Students will likely say that while 3 and "Three" mean the same thing, they are two very different things.
        • One is an actual number, and the other is a word (representing a number).
    • Next, draw 3 === "Three" on the board.
      • Ask students, "Okay, how about 3 === "Three"
        • Students should respond to this question with a similar answer as they did with double equals, ==.
    • Last, draw 3 === "3" on the board.
      • Ask students to spend some time thinking about this comparison.
      • After they’ve spent some time thinking, say:
        • "This example returns False. Why do you think it does that?"
      • It’s important not to ask if 3 === "3" are the same.
        • This is because you need students to think about why this comparison returns false.
        • Given the opportunity, students could spend their time fighting with you about why this example should work.
        • This is because type is a really tricky concept for beginning students.

More about this tip

External Source

Interview with Leo Newball