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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:56:30+00:00 2026-06-12T17:56:30+00:00

I have an enum declared like so: var PlaceType = { PASSABLE_TERRAIN: 1, IMPASSABLE_TERRAIN:

  • 0

I have an “enum” declared like so:

var PlaceType = {
        PASSABLE_TERRAIN: 1,
        IMPASSABLE_TERRAIN: 0,
        SOMEWHAT_PASSABLE_TERRAIN: 2,
        PATH: 3
    };

and a function declared like this:

setPlaceType(placeType) {
        this.clear = false;
        this.placeType = placeType;

        alert("before switch "+(PlaceType.SOMEWHAT_PASSABLE_TERRAIN==this.placeType));
        switch(this.placeType) {
        case PlaceType.PASSABLE_TERRAIN: {
            alert("Case PASSABLE");
            break;
        }
        case PlaceType.IMPASSABLE_TERRAIN: {
            alert("Case IMPASSABLE");
            break;
        }
        case PlaceType.SOMEWHAT_PASSABLE_TERRAIN: {
            alert("Case SOMEWHAT_PASSABLE");
            break;
        }
        case PlaceType.PATH: {
            alert("Case PATH");
            break;
        }
        default: {
            alert("case default");
        }
        }
    }

if I call it like this:

setPlaceType(1);

I get the following alerts: “before switch true”, “case default”

if I call it like this:

setPlaceType(2);

I get the following alerts: “before switch false”, “case default”

In other words, the function is called with the proper argument, which, when doing (what it seems to me to be) the same comparison as the switch but via “==” I get correct behavior, but the switch never matches the values to the appropriate case. Does anybody know why?

  • 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-12T17:56:31+00:00Added an answer on June 12, 2026 at 5:56 pm

    The comparison operator will cast both operands to strings if either operator is a string. If you pass in a string, you are comparing string == number which will cast the number to a string and, in the case of passing the string '2', it will be true.

    switch case comparison uses the identity operator === and will fail if the operands are not the same type.

    long story short, make sure you are always passing a number if your cases are comparing against numbers, you can double check like this:

    setPlaceType(placeType) {
        if (typeof placeType !== 'number') {
            throw new Error('You must pass a number to setPlaceType!');
        }
        ...
    }
    

    also, you should be calling your function like this:

    setPlaceType(PlaceType.PASSABLE_TERRAIN);
    

    otherwise there’s not really any point to using the “enumeration” (i use that term loosely) object.

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

Sidebar

Related Questions

Hi I have an enum declared like this: typedef enum { Top, Bottom, Center
I have a generic type that is parameterized on some Enum, declared like this:
I have declared an enum in my server code, and would like my client
I have enum like this [Flags] public enum Key { None = 0, A
I have enum like this: public enum ObectTypes { TypeOne, TypeTwo, TypeThree, ... TypeTwenty
I have an enum in a file: goog.provide('animals.Fish'); animals.Fish = function(obj) { this.name_ =
In a header I have a setup like this namespace NS { typedef enum
i have a class and have declared an enum in it like public enum
I have declared an enum datatype like: typedef enum TagTypes { BUTTON_TAG_1 = 1,
I often see Simple (non-Flags) Enums declared like this: enum Something { Thingy =

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.