


Next used only var and did not mention any type but assigned the value. If we are not provided the type then it takes the type implicitly based on the value assigned.īelow are the few examples on with and without variable type.įirst created a double variable with var keyword with 3.14 value. When you are using var keyword, that indicates the value can be changed at any time and the variable type is optional. Var keyword is used in the variable declaration. Mainly val is used to define the constants in kotlin.

Kotlin has another keyword ” val” to declare the variables.Īny variable is declared using var that value can be changed at anytime whereas variable declared with val keyword value can not modified one it is initialized. Var is a keyword in kotlin which is used to In this tutorial, We will learn how to create the variables in Koltin for basic types using var.
