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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:10:20+00:00 2026-05-10T14:10:20+00:00

Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();

  • 0

Code:

<html xmlns='http://www.w3.org/1999/xhtml'> <head>     <title>Unusual Array Lengths!</title>      <script type='text/javascript'>         var arrayList = new Array();         arrayList = [1, 2, 3, 4, 5, ];         alert(arrayList.length);     </script>  </head> <body> </body> </html> 

Notice the extra comma in the array declaration. The code above gives different outputs for various browsers:

Safari: 5

Firefox: 5

IE: 6

The extra comma in the array is being ignored by Safari and FF while IE treats it as another object in the array.

On some search, I have found mixed opinions about which answer is correct. Most people say that IE is correct but then Safari is also doing the same thing as Firefox. I haven’t tested this on other browsers like Opera but I assume that there are discrepancies.

My questions:

i. Which one of these is correct?

Edit: By general consensus (and ECMAScript guidelines) we assume that IE is again at fault.

ii. Are there any other such Javascript browser quirks that I should be wary of?

Edit: Yes, there are loads of Javascript quirks. http://www.quirksmode.org is a good resource for the same.

iii. How do I avoid errors such as these?

Edit: Use JSLint to validate your javascript. Or, use some external libraries. Or, sanitize your code.

Thanks to DamienB, JasonBunting, John and Konrad Rudolph for their inputs.

  • 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. 2026-05-10T14:10:21+00:00Added an answer on May 10, 2026 at 2:10 pm

    It seems to me that the Firefox behavior is correct. What is the value of the 6th value in IE (sorry I don’t have it handy to test). Since there is no actual value provided, I imagine it’s filling it with something like ‘null’ which certainly doesn’t seem to be what you intended to have happen when you created the array.

    At the end of the day though, it doesn’t really matter which is ‘correct’ since the reality is that either you are targeting only one browser, in which case you can ignore what the others do, or you are targeting multiple browsers in which case your code needs to work on all of them. In this case the obvious solution is to never include the dangling comma in an array initializer.

    If you have problems avoiding it (e.g. for some reason you have developed a (bad, imho) habit of including it) and other problems like this, then something like JSLint might help.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer userlevel.label maybe? May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer You don't need to use SQL. Just call Drupal's file_create_path('myfile.pdf')… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer you can use the Response.StatusCode property to return a 404:… May 11, 2026 at 11:45 pm

Related Questions

Kindly look at the following code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
For some reason by css link in a webforms master page is getting mangled
According to the CSS 2.1 standard, the vertical margins of floating elements should not
I have following layout: 4 rounded corners background and two panels (left panel and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.