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 9118783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:14:15+00:00 2026-06-17T05:14:15+00:00

So i have been taking a Computer science course that uses C+ to teach

  • 0

So i have been taking a Computer science course that uses C+ to teach programming concepts with. today i learned a new concept that i was not sure applied to JS, in which there are system resources expended each time a string.length is calculated. It seems like a tiny matter but it got me thinking about huge arrays and how that could add up. Check out this example and let me know if loop #2 is indeed more efficient than the first and thanks:

var weekDay = ["Monday", "Tuesday", "Wednesday"];

//for loop #1
for(i=0; i<weekDay.length; i++){
 //code code code
;}

//for loop #2
for(i=0; var n=weekDay.length; i<n; i++){
 //code code code
;}
  • 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-06-17T05:14:16+00:00Added an answer on June 17, 2026 at 5:14 am

    The second approach is faster, but not by much. Also, there is a small syntax error

    for( var i = 0, n = weekDay.length; i < n; i++ ){ ... }
    

    This is rather common in javascript code. Please note the importance in declaring all of your variables with var so that they do not step on the wrong scope.

    You can see this js performance test here: http://jsperf.com/forloopiterator which shows the results being 24% faster when using the second approach.

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

Sidebar

Related Questions

Okay, so far, I have been taking computer science courses in my high school
Me and several friends taking the same programming course have been confused by this
In the data structures class that I am currently taking, we have been tasked
Basically, I've been taking a class on C programming, within that class we use
I'm taking some AI classes and have learned about some basic algorithms that I
I am new to web development and I have been taking a class through
Recently, javaw.exe processes have been taking over my computer and forcing me to exit
In my book (for my computer science course) they have source code snippets. We're
I have been taking a few graduate classes with a professor I like alot
Have been trying to encrypt an xml file to a string so that I

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.