Which of the following expressions correctly uses the logical NOT operator in Swift?
easy📝 Conceptual Q1 of 15
Swift - Data Types
Which of the following expressions correctly uses the logical NOT operator in Swift?
Alet result = not true
Blet result = !true
Clet result = true!
Dlet result = !!true
Step-by-Step Solution
Solution:
Step 1: Understand the logical NOT operator syntax in Swift
In Swift, the NOT operator is represented by a single exclamation mark (!) placed before a Boolean value.
Step 2: Evaluate each option for correct syntax
let result = !true uses !true which is correct. let result = not true uses 'not' which is invalid in Swift. let result = true! places ! after true which is incorrect. let result = !!true uses double !! which is not valid syntax.
Final Answer:
let result = !true -> Option B
Quick Check:
Logical NOT operator = !true [OK]
Quick Trick:Use ! before a Boolean to invert it in Swift [OK]
Common Mistakes:
Using 'not' instead of !
Placing ! after the value
Using double !!
Master "Data Types" in Swift
9 interactive learning modes - each teaches the same concept differently