Skipping Multiple var declarations in JavaScript, Bad?

I’m not sure what bugs me about writing code like the following in JavaScript

var form = button.up('form').getForm(),
    formWindow = button.up('window');
I certainly see it all the time.  Maybe I just need to get use to it.  I always right my code like the following:
var form = button.up('form').getForm();
var formWindow = button.up('window');
I understand wanting to save download bandwidth, but to me it just seems confusing to read.  Am I the only one?

About Peter Kellner

Peter is a software professional specializing in mobile and web technologies. He has also been a Microsoft MVP since 2007. In addition, he’s a multi-course video author at Pluralsight. To read more about Peter Kellner and his experience click here. For information about how Peter Kellner might be able to help you with your project click here.

Follow me:


  1. Peter Kellner says:

    of course Nige. thanks. I fixed that on my post. I think I need to get use to looking at local declarations that way because everyone seems to do that. Eventually, it will look normal to me.

  2. Nige White says:

    Of course it should be

    var form = button.up('form').getForm(),
    formWindow = button.up('window');

    Otherwise you’ll have a global variable there.

    Just looks neater with one var declaration at the top of the function.


Get every new post delivered to your Inbox

Join other followers: