exit() in js?

Discussion in 'JavaScript' started by spaceman12, Mar 16, 2011.

  1. #1
    is there a similar exit function in javascript as it is in php? For instance, when an exit function is called in php, the entire line of code below are ignored. Is there a way to accomplish this in javascript? Thanks :)
     
    spaceman12, Mar 16, 2011 IP
  2. Tanya Roberts

    Tanya Roberts Active Member

    Messages:
    250
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #2
    i guess there is no such a way you can exit(). but you may keep the code in :
    if(<var>!=<your desired output>){
    <here goes your entire body>
    }

    and you can get your output.
    if the condition does not matches, the program will just end as there is no else statement and "}" is the last statement of your program.
     
    Tanya Roberts, Mar 16, 2011 IP
  3. wsrinivas

    wsrinivas Member

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    use return and you can exit a function
     
    wsrinivas, Mar 16, 2011 IP
  4. jkl6

    jkl6 Peon

    Messages:
    70
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just do:
    return;
     
    jkl6, Mar 16, 2011 IP
  5. spaceman12

    spaceman12 Active Member

    Messages:
    60
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    63
    #5
    Thank you all :)
     
    spaceman12, Mar 16, 2011 IP
  6. Jan Novak

    Jan Novak Peon

    Messages:
    121
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    0
    #6
    As I know return is allowed only inside a function.
     
    Jan Novak, Mar 17, 2011 IP
  7. SundayForever

    SundayForever Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks very much!
     
    SundayForever, Mar 17, 2011 IP