I have this code:
var phrase = function (variable, defaultPhrase) {
if (typeof variable === \"undefined\") {
return defaultPhrase;
}
else
In javascript, you typically use the OR operator || to provide an alternative value when a variable is undefined:
return variable || defaultPhrase || ''
In case variable is undefined, it will evaluate to false then the second part of the test will be evaluated, if it is also undefined, you can still return an empty string.