Excellent job! You’ve completed the first lesson of the Data Types & Variables section. Let’s review what was covered.
- A variable declaration consists of a
varkeyword followed by a name, colon and data type.
- A variable initialization occurs when a value is assigned to a variable using the assignment operator (
- A variable declaration and initialization can happen simultaneously on one line or separately.
- A mutable variable is denoted by the
varkeyword and represents a value that is expected to change throughout a program.
- An immutable variable is denoted by the
valkeyword and represents a constant value.
- Kotlin can infer a variable’s type through type inference.
Feel free to utilize the empty Review.kt file and output terminal on the right to hone your understanding of variables and data types and practice writing Kotlin code.
Here are some ways in which you can practice your new knowledge:
- Declare a String variable with the name of your favorite song.
- Declare an Int variable with the minute duration of the song.
- Declare a Boolean variable and assign it
falsedepending on if you’re currently listening to your favorite song!
- Output these values to the terminal.
Think about which of these variables should be declared as mutable or immutable. If you’ve declared them with specified types, try omitting the types and shortening your code.