Bird
0
0

Find the mistake in this Swift code snippet:

medium📝 Debug Q7 of 15
Swift - Operators and Expressions
Find the mistake in this Swift code snippet:
class Fish {}

let f1 = Fish()
let f2 = Fish()

if f1 !=== f2 {
    print("Different fish")
}
AIncorrect operator '!===' instead of '!=='
BUsing '!=' instead of '!=='
CMissing 'let' keyword before f2
DUsing '===' instead of '!=='
Step-by-Step Solution
Solution:
  1. Step 1: Identify operator syntax error

    The operator '!==' is correct for identity inequality; '!=='= is invalid.
  2. Step 2: Confirm correct operator usage

    Replace '!=='= with '!==' to fix the syntax error.
  3. Final Answer:

    Incorrect operator '!===' instead of '!==' -> Option A
  4. Quick Check:

    Use !== for identity inequality, no extra '=' [OK]
Quick Trick: Use !== exactly, no extra '=' at the end [OK]
Common Mistakes:
  • Typing !=== instead of !==
  • Confusing != with !==
  • Missing let keyword (not an error here)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes