Tag Archives: compact-codes

Quick Validating JavaScript Function Before Call

There are many instances where we have to execute a function where we have no idea whether it actually exists or not. Let’s say for example, a function expects another function passed to it as parameter, which would later be executed as callback. A very common usage would be the callback function sent to AJAX requests.

Generally, we would code it with an if-block and check whether the variable (say, callback) is a function or not. If it is, we execute it when we have the work completed (say marked by a variable called workIsDone.)

Continue reading