Announcement

Collapse
No announcement yet.

else if

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • else if

    Perhaps someone with advanced knowledge of JavaScript can resolve this question.

    In many programming languages "else if()" is an integral part of the language. I have not been able to locate it anywhere in the official JavaScript Reference Manual or Guide. Although it often works I suspect that it is not reliable.

    The first version is desirable. The second version is what will always work according to the manual.
    PHP Code:
    if(...)
    {....}
    else if(...)
    {...}

    vs

    if(..)
    {...}
    else
    {
       if(...)
       {...}

    Can someone please shed some light on this issue? Thanks.

  • #2
    Hi Gavisti:

    Yes, the else/if construct, exactly as you outlined it, works just fine in Javascript.

    Chris

    Comment


    • #3
      Chris,

      If I understand your reply correctly, you are stating that the "else if()" construct is valid and fully supported in JavaScript. If that is correct, why is it not in the official manual?


      Thanks.

      gavishTi

      Comment


      • #4
        Hi Gavishti:

        Not sure why it is not in the manual. I know that there are several versions of Javascript so I guess it is possible that it is a version issue.... just not sure. Anyway there are lots of general Javascript examples out there regarding the "else if" construct. Here is one:

        http://www.iota-six.co.uk/javascript/06_condi_s.htm

        Chris

        Comment


        • #5
          Chris,

          Thanks for the link. However, I prefer to use the official manual for JavaScript for verifying key components of the language. I am under the impression the official manual is located at: http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/ Please correct me if I am wrong.

          I believe the problem will begin to show up if you use chained "else if()" statements. Which would tend to verify that it is not supported.
          PHP Code:
          if(...)
          {.....]
          else if(...)
          {.....}
          else if(...)
          {.....}
          else if(...)
          {.....}
          else
          {.....} 
          In other languages that I have used where "else if()" is in the manual the above statement will work. In JavaScript I believe you will find that it does not.


          gavishTi

          Comment


          • #6
            Hi Gavishti:

            I agree completely in terms of being careful, and the manual you referenced is the correct manual as far as I know. All I can say is that I have been using the else/if construct for some time and it has not caused any problems for me (yet).

            Also, it is interesting to note that the Netscape developers themselves use the else/if construct in code that they distribute. See the following link (about 1/2 way down the page just below the comment entitled //*** JAVASCRIPT VERSION CHECK )

            http://www.garden-birds.co.uk/shared...browser.jshtml

            Chris

            Comment


            • #7
              Hi Gavishti,

              Just to add one comment, I also have had no problems using
              the if/else if construct even when chaining them as in your example. Typically if I have to chain too many of them I do switch to a case statement, I find it cleaner, but I have gone 5 deep in the chain before.

              Garth
              Garth

              Comment


              • #8
                Thanks Chris for that link. That is pretty strong evidence that "else if()" is a supported feature. Just wish they would include it in the manual. I have had problems in the past. This tends to indicate the problem was not in the "else if()" statement. Not unusual for JavaScript.

                Comment


                • #9
                  What version of javascript does eSignal support? Or does eSignal reference a version of javascript that's installed as an object in your OS? and the version of javascript therefore is eSignal independent?

                  Also, is there a call I can make which will return the version of javascript that's running?

                  Thanks
                  Standing on the shoulders of giants.

                  Comment


                  • #10
                    Hello Wildfiction,

                    Please read this article, All About JavaScript - The Foundation of EFS from our EFS KnowledgeBase.

                    We do not have the function you're looking for. EFS is an extended version of JavaScript 1.5.
                    Jason K.
                    Project Manager
                    eSignal - an Interactive Data company

                    EFS KnowledgeBase
                    JavaScript for EFS Video Series
                    EFS Beginner Tutorial Series
                    EFS Glossary
                    Custom EFS Development Policy

                    New User Orientation

                    Comment


                    • #11
                      Thanks Jason. I was already using the 1.5 reference manual but didn't want to discover that the reason that I couldn't get things to work was because eSignal's javascript (and extensions etc.) were based on an earlier version.
                      Standing on the shoulders of giants.

                      Comment

                      Working...
                      X