I don’t think there’s anything above TL4.
Mods and Admins are above TL4.
There’s mod (me ), admin and staff
There’s no TL5 for sure;
Unless you consider Mods TL5, that’s true.
Please keep related to Python vs. JS
That is not really a fair comparison, as range is not required for a loop.
for (let i = 1; i < 10; i += 2) console.log(i) // How do you know when each of these are executed?
Or
i = 1
while i < 10:
i += 2
print(i)
Number two yes. The for syntax looks just weird in this case.
That’s true, but I was saying that python’s equivalent of the for (init; condition; increment)
syntax is range(starting, max, increment)
.
while
loops are pretty much standard across all languages
Because in python loops suffer from memory leak. Something that should not happen.
What does that mean?
It means that variables defined/used in a for loop are not deleted when the form loop ends
If you runs this code
for x in range(0, 5):
pass
print(x)
In python instead of giving error, it prints 4. This is memory leaking. If you do loops where lot of data is assigned and used in the loop, the memory is not freed once the loop end.
What about this?
for x in range(0, 5):
pass
del x
Sure it works, but it should not be needed to delete x and 99% of people do not …
That’s also why you should use let
over var
:
for (var i = 0; i < 5; i++) console.log(i);
console.log(i); // 5
for (let i = 0; i < 5; i++) console.log(i);
console.log(i); // ReferenceError: i is not defined
For as much as i dislike JS, it is better in this respect than python,
You like it better than python because there are multiple keywords to define a variable…?
Let and var are not the same thing. From W3School (in case of doubt)
Before ES6 (2015), JavaScript had Global Scope and Function Scope.
ES6 introduced two important new JavaScript keywords:let
andconst
.
These two keywords provide Block Scope in JavaScript.
Variables declared inside a { } block cannot be accessed from outside the block:
Comparing two different loops is not an accurate comparison:
let i = 1;
while (i < 10) {
i += 2;
}
Or
i = 1
while i < 10:
i += 2
Is a fair comparison, in which case we see very little difference and the only preference for one over the other coming down to preference of syntax (brackets or meaningful whitespaces) (and of course bias).