0

For example, this is how it would be done in Python:

for current in range (start, end):

Question: is this the translation to JavaScript?

for(current = start; current < end; current++){}
4
  • 2
    Yes, that's correct. Commented Feb 10, 2016 at 21:30
  • Yes it is the same (the python line is prettier though) Commented Feb 10, 2016 at 21:30
  • The answer was mentioned, but you could test the two, iterate them over something simple and output something Commented Feb 10, 2016 at 21:31
  • 1
    Please refrain from making irrelevant comments in your answer. I feel that your answer was edited to better reflect your intentions at the first place. Commented Feb 10, 2016 at 21:44

1 Answer 1

1

You should always use "use strict" in your JS code. With "use strict", the code must look like:

for(var current = start; current < end; current++){}

Reference for "use strict": https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

Sign up to request clarification or add additional context in comments.

3 Comments

Wrong and wrong. You don't have to use strict mode (but I highly, highly suggest doing so). It's possible that those variables were declared elsewhere. This would be more useful if you stated that they should always declare their variables using var. That is true, otherwise you'll introduce accidental globals.
I nowhere wrote you have to, you should. And only strict mode guards you against re-using a variable or introducing globals where you want locally scoped variables. Telling people what they should do without telling them the way to make it foolproof is simply wrong in my book.
I must be going crazy because I swear it said "have" when I first read it. Sorry. Strict mode doesn't guard you against re-using a variable. Hell, I think you should reuse variables whenever it makes sense. It prevents you from using undeclared variables. Non-strict mode will implicitly create a global but strict mode will throw an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.