Misconception: Students get confused by the multiple equals signs comparison operators in Javascript making it difficult to motivate the difference to beginning students.

Like(223 Likes)
  • 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.
  • Double equals, ==, are simply checking that left and the right are the same.
    • If x = 42, the following comparisons would result:
      • x == 42
        • True
      • x == 5
        • False
  • Scaffold students to evaluating and understanding 3 === "3" using the following steps.
    • 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.