[jQuery] returning true/false in a javascript function
In PHP I'm used to writing functions like:
function checkExistence() {
//query database
if ($exists) {
return true;
} else {
return false;
}
}
Now I started using jQuery with the same javascript checkExistence()
function.
var checkExistence = function() {
//ajax call to a PHP script returning true or false
}
I would then use the function when an event occurs on the page:
$('#element').click(function() {
var exists = checkExistence();
if(exists == true) {
//do something
} else {
//show error message
}
});
I feel it would make my code more readable and more maintainable. But
is this a good thing to do in javascript? Is it überhaupt possible to
return true/false from within a javascript function?