I'm working on some jQuery code that a previous developer wrote. I am trying to understand when/why a person would use commas to separate statements as opposed to semicolons.
In the below example, is it safe to say that there is no benefit to using a comma to separate the statements? If yes...why, if no... is there a situation in which it would make sense to use commas?
FYI: This questions is about chaining statements and whether or not there is a benefit. Not about what the comma does in the statements.
var $some_field_1, $some_child_field, $some_field_2, $some_child_field_2;
function a() {
$some_field_1 = jQuery(".field_class"), $some_child_field = $some_field_1.find("input"), RunSomeFunction(), $some_field_2 = jQuery(".field_class_2"), $some_child_field_2 = $some_field_2.find("input");
}
VS.
var $some_field_1, $some_child_field, $some_field_2, $some_child_field_2;
function a() {
$some_field_1 = jQuery(".field_class");
$some_child_field = $some_field_1.find("input");
RunSomeFunction();
$some_field_2 = jQuery(".field_class_2");
$some_child_field_2 = $some_field_2.find("input");
}
I hope this makes sense. Thanks all!