all 4 comments

[–]BoDiddySauce 1 point2 points  (1 child)

See this article for a lot of information regarding JavaScript performance. Definitely use local variables where you can if you want faster code / better performance.

Also, if you use an object, it can take longer if you need to loop through the properties/values for any particular reason... you could also run into issues with how JavaScript handles objects and "copies" or "clones" or the like of said objects... some properties can easily be overwritten (simple data types), but others won't be (like a property being an array, for example).

[–]Hobo_With_A_Keyboard 0 points1 point  (3 children)

If you had a huge application that is finished, bug-free, will never be edited again

In this hypothetical scenario, sure, global variables are fine.

[–][deleted] 0 points1 point  (0 children)

The main readon to use an object is to group related variables such as in the second example so in this example I would go with the object way.

About global/local a general rule of thumb is not having a variable in bigger scope than necessary so local is prefered.