Coding Friction

Kotlin Variable

Variable is Container to store values, every variable should be declared before using otherwise it gives syntax errors.

variable name should be declared using lowerCamelCase

    var myName = "Coding Friction"

In Kotlin to declare variables use var or val keyword and assign a value with (=) equal operator.

fun main() {
    var color = "Green"
    val name = "Coding Friction"

var – Variable declare with var keyword value can be changed later

val – Variable declare with val keyword value can not be changed later

Scope of a variable –

Variable can be accessed only inside the block of code({….}) where its declared, you can not access outside the block.

Leave a Comment

Your email address will not be published. Required fields are marked *