I've had this little problem where I wanted to check all checkboxes inside a specific area with the help of some javascript and a few jquery functions. I retrieved the value of the "select-all" checkbox and wanted to check/uncheck all other checkboxes under it.
Case 1: status = (elt.checked == true);
This gives me a string with the value "true" or "false" which, when put into a conditional statement, will always be seen as true since it's not an empty string.
Case 2: const status = (elt.checked == true);
This gives me a boolean with the value true or false which can actually be used in the conditional statement.
$(document).on('change', '.select-all input', function(e) {
elt = e.target;
status = (elt.checked == true);
$(elt).closest('.files-list').find('input').each(function(i, e) {
if (status)
$(e).attr('checked', true);
else
$(e).removeAttr('checked');
});
});
Why does this const modifier have any influence on the data type of the variable?