Eslint swears by i in cycles?

Only in the process of learning js, put eslint
As a result, in each cycle except the first one swears an variable i that is already there in the code above.

To look in the direction of the settings for eslint? Or something wrong with cycles can I have?
April 7th 20 at 10:55
2 answers
April 7th 20 at 10:57
Hello! From personal experience I can answer why this is happening. The main reason, as I understand it, the more experienced experts can correct me, this is the scope of variables. The fact is that if you write instead
(const i in names) {
}

(var i in names) {
}

then the variable "i" can be overridden anywhere from where it will access. And if you are in the same block of code (function or method) there are two loop iterations, the probability of error. Also, eslint takes into account the naming conventions. And so, for the PR measure, instead of (const i in names) it is better to write (const name in names) or (const card in cards). In this regard, the code becomes more readable and understandable for Your future colleagues, so if You decide to build a career in IT, You will have to work in a team. I hope I helped You
Only instead of const - let. If const, then i will not change - Edward.McLaughl commented on April 7th 20 at 11:00
@Bulah.Parisian90, and it is in this cycle and should not be changed. - janie.Treutel60 commented on April 7th 20 at 11:03
April 7th 20 at 10:59
Variables of the form "i, x, j etc." - such a decision, it should be said. First, it is easy to pile up doubles (as in this case), and confusing (what kind of variable), if part of the code is quite long, and there are more than two variables.
It is the local variables inside the loop is designed to increment. They can not be confused. Everyone always wrote. Then suddenly it became a problem? Curious how you affectionately referred to as the increment? - antonetta.Bradtke commented on April 7th 20 at 11:02
@Jeanette_Simon, this is what kind of increment in the "names"? the variables in "names" I called, as "name", obviously. - janie.Treutel60 commented on April 7th 20 at 11:05
@Santina28, Where did you find that we are talking about the for in loop? Where it says in the question? There is clearly talking about the classic cycle and I'm talking about it. When the cycle object it is clear that there are using something more meaningful. - antonetta.Bradtke commented on April 7th 20 at 11:08

Find more questions by tags JavaScript