QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Home
  • QIdea
  • QTrack
Home Carbon Ads JavaScript Function Techniques You May Not Know

JavaScript Function Techniques You May Not Know

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.

function myFunc()
{
    //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:

(function () {
    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:

(function (window, document, undefined) {
    //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.

Jul 24, 2014Narayan Prusty
JavaScript Global Variables And Memory LeakagePassing Arguments To JavaScript Files
Comments: 0

    Leave a Reply Cancel reply

    To create code blocks or other preformatted text, indent by four spaces:

        This will be displayed in a monospaced font. The first four
        spaces will be stripped off, but all other whitespace
        will be preserved.
        
        Markdown is turned off in code blocks:
         [This is not a link](http://example.com)
    

    To create not a block, but an inline code span, use backticks:

    Here is some inline `code`.

    For more help see http://daringfireball.net/projects/markdown/syntax

    Narayan Prusty

    I am a software engineer specialising in Blockchain, DevOps and Go/JavaScript. This is my personal blog where I write about things that I learn and feel interesting to share.

    8 years ago 1 Comment Web Development
    Share this
    0
    GooglePlus
    0
    Facebook
    0
    Twitter
    0
    Linkedin
    • arguments Variable
    • Immediately-Invoked Function Expression
    Related Articles
    • JavaScript Global Variables And Memory Leakage
    • Creating A Page Load Indicator
    • Javascript “use strict” Tutorial with Examples
    • JavaScript “let” Keyword
    • Creating JavaScript Modules
    Our Sponsor
    My Books

    2014 - 2015 © QNimate
    All tutorials MIT license