R

Ravina • 2.56K Points
Extraordinary

Q. What does the following Swift code print?

Code:
let name: String? = nil
print(name ?? "Unknown")
  • (A) nil
  • (B) Unknown
  • (C) name
  • (D) Optional("Unknown")
  • Correct Answer - Option(B)
  • Views: 1
  • Filed under category Swift (iOs)
  • Hashtags:

Explanation by: Ravina
The `??` operator provides a default value if the optional is nil. So, it prints 'Unknown'.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.