3
//code 1
var pacientes = document.querySelectorAll(".paciente");
for(var i = 0; i < pacientes.length; i++){
var paciente = pacientes[i]; //linha desnecessária
paciente.classList.remove("invisivel");
}
//Code 2
var pacientes = document.querySelectorAll(".paciente");
for(var i = 0; i < pacientes.length; i++){
pacientes[i].classList.remove("invisivel");
}
Above has two snippets of different code, take a code in JS where I saw that this practice was common in several snippets of code, declare a variable receiving the element of array var paciente = pacientes[i];
, but I find it much more practical to put the element of array in its position and remove it from the class: pacientes[i].classList.remove("invisivel");
, as we see in the second code.
As the code was well structured I was in doubt if this would be a good practice (if yes, why? because I can’t see good practice in this), or it would only be to leave the code more didactic.
I understand, my line of thought is like yours, I don’t like to create unnecessary variables.
– Ian Ribeiro