I'm fairly new to JavaScript and I wonder if there is a way to write this function shorter and better?
function checkFile(file){
var cbEnab= true;
if (file !== undefined && file !== null) {
cbEnab = (!jQuery.endsWith(file, "Com.js"));
}
return cbEnab;
}
if (!file)
. Also, the bracers around the definition ofcbEnab
seem unnecessary, don't they? – Ivo Coumans Feb 10 at 9:45if (!file)
would work, but changes the behavior a bit. Eliminating braces would also work, but it's poor programming practice. – 200_success♦ Feb 10 at 15:56()
, not the curly braces{}
. Didn't know that!file
would be different! – Ivo Coumans Feb 11 at 7:24