Swift - Variables and Constants
You want to store the number of days in a week as a constant in Swift. Which code correctly declares this and prevents accidental changes later?
let declares a constant that cannot be changed after assignment.let daysInWeek = 7
// daysInWeek cannot be changed later declares and assigns daysInWeek with 7 and prevents changes later. var daysInWeek = 7
// Later changed to 8 accidentally uses var which allows changes. constant daysInWeek = 7
// Prevents changes uses invalid keyword. let daysInWeek
// Assign value later declares without assignment, which is invalid for constants.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions