let and var in Swift?let declares a constant, which means its value cannot change after it is set. var declares a variable, which means its value can change.
Type inference means Swift automatically figures out the type of a variable or constant based on the value you assign to it, so you don't always have to write the type explicitly.
score with an initial value of 10 using type inference?You write: var score = 10. Swift infers that score is an Int because 10 is an integer.
let after it is set?No, once a constant is set with let, its value cannot be changed. Trying to do so causes a compile-time error.
let instead of var when possible?Using let helps keep your code safe and predictable because constants cannot change unexpectedly. It also helps the compiler optimize your code.
var declares a variable that can change. let declares a constant.
let name = "Alice"?Because "Alice" is text, Swift infers the type String.
let constant after setting it?Swift prevents changing constants by giving a compile-time error.
All are correct. var age = 25 uses type inference. var age: Int = 25 explicitly sets type. let age = 25 declares a constant.
let over var when possible?Using let helps avoid bugs by preventing accidental changes to values.
let and var in Swift and why you would choose one over the other.