A few useful JS tricks

Javascript
  1. always use === instead of ==

There is no conversion when using the === (or !==) operator. It might be argued that it compares the value and the type faster than ==

** 2. Transform the arguments object into an array**

var argumentsArray = Array.prototype.slice.call(arguments);

3. Make using strict a habit.

You must use strict if you want to be alerted everytime you violate JavaScript when writing code. By enforcing regulations such as declared variables, it aids in maintaining programming decorum.

"use strict"; // Things might go chaotic

(function (){
    "use strict";
    // You are in control and write a better piece of code
})();

4. Avoid using with()

By using with(), a variable is added to the global scope. As a result, if two variables share the same name, it may be confusing and the value may be replaced.

5. Use a switch/case statement rather than a succession of if/else statements.

6. An HTML escaper function

function escHTML(text) {  
    var repl= {"<": "&lt;", ">": "&gt;","&": "&amp;", """: "&quot;"};                      
    return text.replace(/[<>&"]/g, function(character) {  
        return repl[character];  
    }); 
}