Recall & Review
beginner
What does the
let keyword do in Swift?The let keyword declares a constant, which means its value cannot be changed after it is set.
Click to reveal answer
beginner
What happens if you try to change a
let constant after it is set?Swift will give a compile-time error because constants cannot be modified once assigned.
Click to reveal answer
beginner
How do
let and var differ in Swift?let declares a constant (immutable), while var declares a variable (mutable).
Click to reveal answer
beginner
Example: <br><code>let pi = 3.14</code><br>Can you change <code>pi</code> later in the code?No, because pi is declared with let, it is a constant and cannot be changed.
Click to reveal answer
beginner
Why use
let instead of var when possible?Using let helps prevent accidental changes and makes your code safer and easier to understand.
Click to reveal answer
What keyword declares an immutable value in Swift?
✗ Incorrect
let declares a constant that cannot be changed.
What happens if you try to assign a new value to a
let constant?✗ Incorrect
Swift prevents changing constants by giving a compile-time error.
Which keyword allows you to change the value after declaration?
✗ Incorrect
var declares a variable that can be changed.
Why is it good to use
let when possible?✗ Incorrect
Using let helps keep values safe from accidental changes.
Which of these is a correct constant declaration in Swift?
✗ Incorrect
let name = "Alice" correctly declares a constant.
Explain what
let does in Swift and why it is useful.Think about how constants help avoid mistakes.
You got /4 concepts.
Describe the difference between
let and var in Swift.One can change, the other cannot.
You got /4 concepts.