The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Where do you place global variables?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #45475


    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


    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).


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

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.