I’ve got JavaScript code like this =>
(function(){
document.getElementById("element").onclick = function(){
var r = confirm("Are you sure ?");
if (r){
return true;
} else {
return false;
}
}
})();
this script works, but just gives me notification about Strict Warning that anonymous function doesn’t always return a value
I’m interested in what that means, how can I prevent this and will it provoke any problem ? Please any ideas ? thanks 🙂
It’s not because of the anonymous function, it’s because the
elsewith thatreturnis redundant. You don’t need it since return exits the function, if theifstatement is not true then the defaultreturnwill execute.Edit:
As nebulae said this can be done even shorter: