I’m back with what is probably a boneheaded question. I’m reviewing the module on conditional statements (JavaScript is kicking my butt and I realized I needed to go back to the top of the unit and review what I’d learned because it just wasn’t sticking), and here’s what it says:
“Say you have a website and want to take a user’s username to make a personalized greeting. Sometimes, the user does not have an account, making the username
variable falsy. The code below checks if username
is defined and assigns a default string if it is not:”
And then the code that follows looks like this:
let username = ‘’;
let defaultName;
if (username) {
defaultName = username;
} else {
defaultName = ‘Stranger’;
}
console.log(defaultName); // Prints: Stranger
What’s perplexing me is how “let defaultName” is a complete idea. Is it because the variable is assigned later with “defaultName = ‘Stranger’;”? Or is prefacing it with “let” enough for me to speak defaultName into existence? Thanks in advance for any input you can offer.