What is the difference between `let` and `var` in swift?

后端 未结 30 1322
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 11:09

What is the difference between let and var in Apple\'s Swift language?

In my understanding, it is a compiled language but it does not check

30条回答
  •  轮回少年
    2020-11-22 11:57

    A value can be reassigned in case of var

     //Variables
     var age = 42
     println(age) //Will print 42
     age = 90
     println(age) //Will Print 90
    

    ** the newAge constant cannot be reassigned to a new value. Trying to do so will give a compile time error**

    //Constants
    let newAge = 92 //Declaring a constant using let
    println(newAge) //Will print 92.
    

提交回复
热议问题