Kann ich dieselbe Variable in unterschiedlichen for-Schleifen in JavaScript zweimal deklarieren? [Duplikat]

Mögliche Duplikate:
JavaScript-Variablenbereich

Ich habe eine JavaScript-Funktion für HTML-Auswahloptionen für Tage:

// Show and hide days according to the selected year and month.
function show_and_hide_days(fp_form) {
    var select_year= $(fp_form).find("select.value_year");
    var select_month= $(fp_form).find("select.value_month");
    var select_day= $(fp_form).find("select.value_day");
    var selected_year= $.parse_int($(select_year).val());
    var selected_month= $.parse_int($(select_month).val());
    var selected_day= $.parse_int($(select_day).val());
    var days_in_month= new Date(selected_year, selected_month, 0).getDate();
    // If the number of days in the selected month is less than 28, change it to 31.
    if (!(days_in_month >= 28))
    {
        days_in_month= 31;
    }
    // If the selected day is bigger than the number of days in the selected month, reduce it to the last day in this month.
    if (selected_day > days_in_month)
    {
        selected_day= days_in_month;
    }
    // Remove days 29 to 31, then append days 29 to days_in_month.
    for (var day= 31; day >= 29; day--)
    {
        $(select_day).find("option[value='" + day + "']").remove();
    }
    for (var day= 29; day <= days_in_month; day++)
    {
        $(select_day).append("<option value=\"" + day + "\">" + day + "</option>");
    }
    // Restore the selected day.
    $(select_day).val(selected_day);
}

Meine Frage ist: Kann ich "var day" zweimal in zwei verschiedenen for-Schleifen deklarieren und welchen Umfang hat diese Variable? Ist es legal und was passiert, wenn ich dieselbe Variable zweimal in derselben Funktion deklariere? (innen für Loops oder außen für Loops)? Was passiert zum Beispiel, wenn ich eine der Variablen erneut mit "var" deklariere?

Was passiert, wenn ich "var" vor dem variablen Tag in for-Schleifen überhaupt nicht verwende?

Danke, Uri.

P.S. $ .parse_int ist ein jQuery-Plugin, das parseInt mit radix 10 aufruft, wenn es nicht angegeben ist.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage