September 2011

Mistakes On Chain Assignment In javascript

One common mistake that I see developers do is exposing a variable to the Global object in chain assignment. first I let’s see how can you expose a variable to the Global object by accident.   function test(){ a =12; // var is missing return a; } test();   By missing the keyword var even(…)

Namespace in jQuery

I have implemented a jQuery plugin that will take care of namespacing for us. if you don’t know what is namespace please read it from here take a look at the code below. and see how it works. you can get the code from jsfiddle as well $.namespace("liteframe.actions.controller"); //OR this way. $.namespace(["liteframe.actions.controller","cake.action.jump"]); //OR this way.(…)

Removing elements from an array in javascript

If you are trying to remove elements from an array. and do not care what those elements are, you shouldn’t use array slice, array splice. however there is an easier way of doing this. by just changin the length of an array we can modify our array and remove items from it.   var arr(…)

Repeating a string without using a for loop in javascript

Even though it is not recommended to use Array constructor. but sometimes we can get some usage of it. One good example would be repeating a string without using a for loop. in this example we are creating an empty array with default undefined values. ( when you specify a size for an array, without(…)

Securing Undefined Variable In Javascript

Sometimes some bad programmer or some hacker messes up with the undefined global variable in javascript. so why would we really care about it. the following are some examples that the variable undefined will be returned     var myVar = undefined; //Anything that has been set to the value of undefined.   function test(){};(…)

Type Casting In Javascript

I see a lot of confusion among the javascript developers when it comes to casting in javascript. Casting To A Number let’s say you have a String and you want to convert it to a Number. one would say I will use parseInt() or parseFloat(). but there is even an easier way of doing it.(…)