In this post I will provide list of JavaScript function features which you may not know:
arguments Variable
arguments variable is a variable available inside every function that contains reference to all the arguments passed during function call. Its a array like object.
{
//length property returns number of arguments
for(var count = 0; count < arguments.length; count++)
{
//arguments can be accessed using [] operator.
console.log(arguments[count]);
}
}
myFunc("1", 2);
Immediately-Invoked Function Expression
IIFE is an anonymous function that is immediately invoked during runtime. An example of IIFE:
console.log("QNimate");
})();
IIFE is often used in libraries to start them functioning automatically. This allows libraries to execute in a function scope and therefore don’t need to declare any global variables.
This is what we would usually see in large libraries:
//library code here
})(window, document, undefined);
Here we are passing most commonly used global variables(window, document and undefined) to the function and making them local inside the function body because local variables are faster to resolve than the global variables. But this is noticed in huge scale and also if you are referencing global variables a lot.
Conclusion
I will be adding more techniques as I will come through. Thanks for reading.