let firstName = “Ted”
var lastName: String
if firstName == “Ted” {
lastName = “Healy”
} else if firstName == “Moe” {
lastName = “Howard”
}
let fullName = firstName + " " + lastName
+++++++++++++++++++++++++++++++++++
I wonder why the code above is having error “variable ‘lastName’ used before being initialized”
and it will worked when I initialise
var lastName: String = “”
isn’t that variable lastName filled with value inside if else statement and by the time it called to assign fullName constant it already have value? why I should fill empty string “” to make this worked?