3

I saw the following snippet in a jquery code, but I don't understand why it uses a comma right before 'contents' instead of a period.

var that = $(this),
contents = that.serialize();

Does anyone have an idea why a comma is being used?

I am missing the words to search properly I think.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
JSnewb
  • 31
  • 2
  • "Comma Trick" reference: http://blog.vjeux.com/2011/javascript/javascript-comma-trick.html – showdev Aug 29 '13 at 22:05
  • `var`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var – Ian Aug 29 '13 at 22:10

2 Answers2

4

same as :

var that = $(this);
var contents = that.serialize();
TecHunter
  • 6,091
  • 2
  • 30
  • 47
  • Thanks alot you both, I am new to this thanks! Sorry if this was a duplicate, but without the proper knowledge this is hard for a newbie to see. – JSnewb Aug 29 '13 at 22:06
4

You can use it to declare multiple variables, it's just shorthand for:

var that = $(this);
var contents = that.serialize();

Many other languages support the same.

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148