Advice from a Senior Dev Stop Using the Implicit Else
function checkCountryCodeImplicit(country) {
if (country === "United States") {
return "+1";
}
if (country === "Uruguay") {
return "+598";
}
if (country === "Uzbekistan") {
return "+998";
}
// It's easy to forget what the condition for this return is!
return "+44";
}
->
function checkCountryCode(country) {
if (country === "United States") {
return "+1";
} else if (country === "Uzbekistan") {
return "+998";
} else if (country === "Uruguay") {
return "+598";
} else if (country === "United Kingdom") {
return "+44";
} else {
// This alerts us if a country is passed in that our function hasn't handled
throw new Error("This input is not supported at the moment.");
}
}