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 Quick Validating JavaScript Function Before Call

Setting Default Variable Value in JavaScript

Often, there are conditions where we need to provide a default value of a variable if it is undefined. As a case study, we will take up the situation, where we are passing a Boolean value to function and if the input is true, some action has to be taken. In case someone does not pass any value, the input is assumed to be true.

Continue reading Setting Default Variable Value in JavaScript

String Reversing Algorithm Performance In JavaScript

Wherever performance is the key factor, choosing the right algorithm, (in a very unbiased fashion,) is a very crucial factor. And generally for reversing string in JavaScript applications, I endorse this petite string reversal algorithm using Array.reverse() method.

Continue reading String Reversing Algorithm Performance In JavaScript

Clearing Print Queue in Windows

It has happened with me a number of times that documents got stuck in my print queue like super-glue1!

Perhaps it was the wrong document or maybe the wrong printer chosen. In any case, going to printer options and cancelling/deleting the print would result in all but the last document being stuck at “deleting…” state in the printer queue. Nothing would remove that last document from the list of print jobs. And you know that until that small little document is not cleared off the list no other work can be done without getting distracted! Continue reading Clearing Print Queue in Windows

  1. http://en.wikipedia.org/wiki/Cyanoacrylate []