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

  • Home
  • SEARCH
  • 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 6911897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:01:00+00:00 2026-05-27T09:01:00+00:00

What does the : mean in the 3-6th lines below? function displayError(error) { var

  • 0

What does the “:” mean in the 3-6th lines below?

function displayError(error) {
    var errorTypes = {
        0: "Unknown error",
        1: "Permission denied",
        2: "Position is not available",
        3: "Request timeout"
    };
    var errorMessage = errorTypes[error.code];
    if (error.code == 0 || error.code == 2) {
        errorMessage = errorMessage + " " + error.message;
    }
    var div = document.getElementById("location");
    div.innerHTML = errorMessage;

}
  • 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-27T09:01:00+00:00Added an answer on May 27, 2026 at 9:01 am

    The variable errorTypes is an object literal. The : separates the object property name (the numbers) from its value. If you are familiar with hash tables in other languages, this structure is a similar concept. Or in PHP, for example, this could be represented as an associative array.

    You can do:

    var errorTypes = {
        0: "Unknown error",
        1: "Permission denied",
        2: "Position is not available",
        3: "Request timeout"
    };
    
    console.log(errorTypes[0]);
    // Unknown error
    
    console.log(errorTypes[2]);
    // Permission denied
    

    Note that the normal syntax for referencing an object property (using the dot operator) won’t work for these numeric properties:

    // Won't work for numeric properties
    errorTypes.0
    SyntaxError: Unexpected number
    
    // Instead use the [] notation
    errorTypes[0]
    

    In this instance, since numeric property names were used, the whole thing could have been defined as an array instead and accessed exactly the same way via the [] notation, but with less syntactic control over the keys.

    // As an array with the same numeric keys
    var errorTypes = [
        "Unknown error",
        "Permission denied",
        "Position is not available",
        "Request timeout"
    ];
    console.log(errorTypes[2]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does [_\s^] mean underscore and whitespace but not (quote) in Reg I understand that
What does * mean in the function signature _.extend(destination, *sources) See here for an
What does mean this Reasharper error? I just upload project from svn repository.
What does mean? I get this error when trying to iterate through a file
Does that mean that I can't share a Form between delphi 2007 and 2009?
Does it mean search the previous folder for somefile.h or the project folder for
What does it mean when you get or create a date in UTC format
What does it mean if a task is declared with the automatic keyword in
What does it mean when a PostgreSQL process is idle in transaction? On a
What does it mean when it gives a backtrace with the following output? #0

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.