I use

var foo = 5;

to create a local variable and

window.foo = 6;

to create a global variable. If I thought my code would be run outside of a
browser then I'd create a global object as Dmitry P suggested.

This way it's very explicit when you want something to be global - otherwise
you should always be using `var`. For me it's not a technical consideration
- it's about readability.

On 7 January 2011 07:46, Mathias Bynens <math...@qiwi.be> wrote:

> You’re in the global scope, and you want to create a new global var.
> There are different options. What is the difference between them?
>
>
-- 
Nick Morgan
http://skilldrick.co.uk
@skilldrick <http://twitter.com/skilldrick>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to