• Quick Validating JavaScript Function Before Call

    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…

  • Setting Default Variable Value in JavaScript

    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…

  • Infinite Ways to Detect Array in JavaScript

    Infinite Ways to Detect Array in JavaScript

    JavaScript (ECMA script in general) is a miraculous language. It allows us to prove that coding is creativity. One reason for that is the numerous ways a single objective can be coded. For instance, checking whether a variable is an Array, can be done in four different ways. And probably more! Some months back I…

  • Optimized Trapping of Undefined-like Values In JavaScript

    While working on the FusionCharts JavaScript charts, there was a frequent need to test whether a variable was null, undefined, NaN or an empty string. The “frequent” need was so frequent that the probing function alone took up 15% of the chart’s execution time.

  • JavaScript Optimisation – Destructive vs Indexed Array Iteration

    JavaScript Optimisation – Destructive vs Indexed Array Iteration

    In number of JavaScript applications, developers are found to use destructive array iteration for the sake of readability and simplicity of codes. However, usage of the same is not always conducive towards the performance of the code.

  • Convert FusionCharts Data-XML To JavaScript Array

    Convert FusionCharts Data-XML To JavaScript Array

    This is a snippet of JavaScript that would allow you to easily retrieve all “set” values from a FusionCharts data-XML in form of an Array. One can use it to perform various mathematical or visual operations by retrieving the data-XML from FusionCharts object using the getXMLData() method and then passing on the same to this…

  • 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.

  • Fast Algorithm To Find Unique Items in JavaScript Array

    When I had the requirement to remove duplicate items from a very large array, I found out that the classic method to be not optimised as it took a pretty long time than desired. So, I devised this new algorithm that can sort a large array in a fraction of the original time.

  • Generating Pareto Chart Data for FusionCharts

    Generating Pareto Chart Data for FusionCharts

    As soon as I read about Pareto Charts on FusionCharts blog and how it uses cumulative percentage on a dual-y axes graph to allow users to summarize data into segments, I realized that a simple script to generate the FusionCharts XML would help users generate such graphs. For those who do not know what is…

  • How to design good APIs

    How to design good APIs

    If you haven’t already read Why to Design a Good API and Characteristics of a well designed API I recommend doing so. As discussed in the article, APIs are essentially permanent and should not be modified once distributed. You mostly have one chance to get it right.

  • Load jQuery Plugins Only When Required (Runtime)

    I have often observed that websites that are template-driven (like blogs, cms, etc), tend to load all the required scripts and css in every page. One such example would be WordPress blogs with plugins for various types of content processing (overlay, tooltip, animation, etc.) Every page of such a WordPress driven site loads the relevant…

  • Optimising JavaScript (part 1)

    Optimising JavaScript (part 1)

    In my years of experience in programming, I have observed that certain performance ‘tweaks’ work best for certain languages. This is mostly due to the nature of the interpreter ((Interpreters are programs that execute codes one line at a time. See: Interpreter in Wikipedia))/compiler ((a program that decodes instructions written in a higher order language.…