All Posts by Email, Once a Week

Media Temple logo

CSS-Tricks is brought to you in part by Media Temple, the web hosting that we both use and recommend.

Where do you place global variables?

  • # June 12, 2013 at 1:09 pm


    Curious to know if there is a preferred practice for the location of global variables. I like to organize variables at the top of all my functions…just inside the document ready. Is this the best method? Or is it better to place variables right before the associated function?

    Any advice is welcome…thank you

    # June 12, 2013 at 1:16 pm

    I put all global variables at the top of the JS file, before the document ready (unless, of course, they require the document to be ready).

    # June 12, 2013 at 3:44 pm

    As a general rule, I avoid global variables whenever possible, to keep things neatly organized and prevent potential name conflicts.

    # June 12, 2013 at 7:06 pm

    This reply has been reported for inappropriate content.

    Ok…thanks for the advice!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed