In such a record, both functions will "see" only their variables, if there are two, etc. identical variables by name, or not?

$(document).ready(function(){ $('input[data-size]').change(function() { var shed = $('#size1:checked'); var lumber = $('#size2:checked'); var country = $('#size3:checked'); var brick = $('#size4:checked'); var carriage = $('#size5:checked'); }); $('input[data-type]').change(function() { var shed = $('#type1:checked'); var lumber = $('#type2:checked'); var country = $('#type3:checked'); var brick = $('#type4:checked'); var carriage = $('#type5:checked'); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

  • 3
    Yes, they will only see their variables. - Regent

1 answer 1

when using the keyword var variable is declared at the function level and is not visible from the outside.

In this case, two different functions are passed to the handlers, inside which variables are created.

Since all variables are declared inside functions, they are not visible from the outside and, therefore, do not overlap with each other.