I converted my CoffeeScript code to JavaScript using http://js2coffee.org
ResetControls = ->
$("#menu_item_url").val ""
$("#menu_item_name").val ""
$("#resource_id").prop "selectedIndex", 0
$("#resource_type_id").prop "selectedIndex", 0
It converted it to:
var ResetControls;
ResetControls = function() {
$("#menu_item_url").val("");
$("#menu_item_name").val("");
$("#resource_id").prop("selectedIndex", 0);
return $("#resource_type_id").prop("selectedIndex", 0);
};
The first line in the converted JavaScript code suggests that its some kind of a best practice to put var keyword before variable name, when assigning function to a variable. Is it so? How?
In my understanding, var
comes handy in recursive calls where your intention is to make copies of variables inside the recursive function (otherwise they will be shared or remain static between the recursive calls ).
Is there any other significance of var
?