When working with nullable values, you use the safe call operator ?. and the Elvis operator ?: to avoid crashes. Once you understand these two, you can handle API responses, optional user profile data, and database fields more safely.
kotlin
fun main() {
val name: String? = null
val length = name?.length
println("Length: $length")
val displayName = name ?: "Guest User"
println("Welcome, $displayName")
}You should see
Length: null Welcome, Guest UserSummary
Don't handle nullable values directly. Use ?. and ?: to build a safe path instead.