1
I’ll tell you what:
var d = new Date();
var dataInicial = new Date(2017, 5, 1);
var dataFinal = new Date(2017, 5, 20);
var percorreDatas = function(){
d = dataInicial;
while(d <= dataFinal){
d.setDate(d.getDate()+1);
console.log("d", d);
console.log("dataInicial", dataInicial);
}
}
percorreDatas();
Why is the variable "starting date" updating along with the variable "d", if I don’t increment it??????
This is because Javascript objects behave as a reference and not "as a value". I will try to detail an answer
– Guilherme Nascimento