Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7510271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:10:54+00:00 2026-05-29T23:10:54+00:00

I haven’t done serious JavaScript programming in a while, and I am writing an

  • 0

I haven’t done serious JavaScript programming in a while, and I am writing an intro guide to the language for some of my colleagues. I’d like to discuss loop best practices, but there is one small detail I’ve kept in the back of my head:

When looping over arrays, I remember the following pattern not being safe to use because there are major browsers that don’t support it:

for (var i = 0; i < ls.length; i++) { ... }

Instead, the var keyword must be moved out of the array, as such:

var i;
for (i = 0; i < ls.length; i++) { ... }

Is this correct? I’ve scoured the net and cannot confirm this. Do some old browsers not support the first method? If not, which ones do not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:10:55+00:00Added an answer on May 29, 2026 at 11:10 pm

    “Is this correct?”

    Unless we’re talking about some really, really old browser, I’m not aware of any such issue with browsers in use today.


    The only issue people likely have with the first example is that it may confuse someone into thinking that JavaScript has block scope, which it doesn’t This changed since ES6, which does have block scope.

    In either example, the i variable will be scoped to the enclosing variable environment, whether the enclosing environment is a function, or the global environment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Haven't done serious JavaScript since 90s, so looks like a couple of things changed.
Haven't done ASP.NET development since VS 2003, so I'd like to save some time
I haven't done a lot of .NET programming, but I've examined a few of
Haven't done as much of Javascript as I should have done. I am trying
haven't done much jquery and ran into a problem. I'd like to bind hover
I haven't done C++ in a while and can't figure out why following doesn't
Haven't done an app in a couple of years and I feel like I'm
Haven't been programming in JS for a while. Now, I have following thing: <html>
I haven't done a lot of work with multi-level, pure CSS drop-down menus before,
I haven't found any documentation on this or seen this done before, but is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.