{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Test: Swift - Nil Coalescing Operator

3. var vowels = [“a”, “e”, “i”, “o”, “u”]; var vowel = vowels[5] ?? “a” — What’s in vowel?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: Crash
Explanation
The index range of the array vowels goes from 0 to 4. So, vowels[5] does not exist. In case of arrays going over the max index will be a fatal crash. It does not return nil. If it returned nil, then ?? operator would have returned a. If the index was 4 instead of 5, the value returned would have been u.
Take the Test
Take the complete test on this topic. You will be able to review answers to questions and get a test score.

Take the Test


Question 3 of 5


Test is Based on this Article
icon-swift-article.jpg
This article talks about the Nil Coalescing Operator (??) in Swift.
icon-swift-test.jpg
Test on Nil Coalescing Operator for Optionals.

More Articles With Similar Tags
icon-swift-test.jpg
Test on Nil Coalescing Operator for Optionals.
icon-swift-article.jpg
This article talks about unwrapping the optionals in Swift implicitly and the circumstances where you would use this functionality.
icon-swift-article.jpg
This article discusses the safer ways of unwrapping an optional in Swift that includes Optional Binding.
icon-swift-article.jpg
This article talks about optional chaining in swift where multiple optionals can be chained together and fail gracefully by returning nil when one of them is nil.
icon-swift-article.jpg
Summary of three operators (?, !, ??) used in optionals in Swift.
                                                                                                                                                                                                             
About  Contact  Privacy Policy  Site Map