Written By: @Ashley
**The Basics Optionals Structs Closures Additional Resources**
<aside> 💡
To do the fun stuff, you always got to start with the basics! :)
</aside>
<aside> 💡
Optionals are a data type in Swift where a variable may or may not have a value. Any of the data types in the **Data Types** section can become an optional. Declaring an optional is done by including the data type name followed by a question mark ?
just like in the code snippet below.
If an optional has no value, that means the optional is nil
.
</aside>
var title: String = "Green Eggs and Ham"
var authorOfBook: String? = nil
Wait, but what’s the difference between String
and String?
?