Back to questions
JuniorTheoryCommon
What does the program print?
let a = Int("0") ?? 5
let b = Int("five") ?? 5
print(a, b)0 5
- Expecting
5 5: treating0as an empty value.??takes the default only fornil, andInt("0")holds the real number0. - Expecting
Int("five")to give0or to crash the program: a text that is not a number givesnil, and??puts5in its place.
- What does
Int("five")return on its own, before??is applied? - How would you write the second line with
if letinstead of???