val and var in Kotlin?val declares a read-only variable (like a constant). You cannot change its value after assignment.<br>var declares a mutable variable, so you can change its value later.
Null safety means Kotlin helps you avoid errors caused by null values by distinguishing nullable and non-nullable types at compile time.
null in Kotlin?Use a question mark ? after the type. For example, var name: String? means name can be a string or null.
null to a non-nullable variable?Kotlin will show a compile-time error. Non-nullable variables cannot hold null values.
Use the safe call operator ?.. It only calls the property or method if the variable is not null, otherwise returns null.
val declares a read-only variable that cannot be reassigned.
email?Use String? to allow null values. var email: String? means email can be changed and can be null.
null to a non-nullable variable?Kotlin prevents assigning null to non-nullable variables at compile time.
The safe call operator ?. accesses properties only if the variable is not null.
!! operator do in Kotlin?The !! operator asserts a value is not null and throws an exception if it is.
val and var in Kotlin and when to use each.