Bird
0
0

What does the identity operator === check in Swift?

easy📝 Conceptual Q11 of 15
Swift - Operators and Expressions
What does the identity operator === check in Swift?
AIf two variables are of the same type
BIf two variables have the same value
CIf two variables refer to the exact same class instance
DIf two variables are both nil
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of ===

    The === operator checks if two references point to the same object in memory.
  2. Step 2: Differentiate from value equality

    Unlike ==, which checks value equality, === checks identity (same instance).
  3. Final Answer:

    If two variables refer to the exact same class instance -> Option C
  4. Quick Check:

    === checks identity [OK]
Quick Trick: Remember: === means same object, not just same value [OK]
Common Mistakes:
  • Confusing === with == for value equality
  • Using === with structs or value types
  • Thinking === checks type equality

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes