Bird
0
0

Which of the following is the correct syntax to negate a Boolean value isActive in Swift?

easy📝 Syntax Q12 of 15
Swift - Operators and Expressions
Which of the following is the correct syntax to negate a Boolean value isActive in Swift?
A!isActive
Bnot isActive
CisActive!
DisActive.not()
Step-by-Step Solution
Solution:
  1. Step 1: Recall the NOT operator syntax

    In Swift, the NOT operator is written as an exclamation mark (!) placed before the Boolean variable to flip its value.
  2. Step 2: Check each option

    !isActive is the correct syntax. The other options are not valid Swift syntax for negation.
  3. Final Answer:

    !isActive -> Option A
  4. Quick Check:

    NOT = ! before variable [OK]
Quick Trick: Use ! before variable to negate Boolean [OK]
Common Mistakes:
  • Writing 'not' instead of '!'
  • Putting ! after variable name
  • Using method calls like .not()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes