Skip to main content
1-Visitor
April 24, 2015
Question

Javascript return

  • April 24, 2015
  • 1 reply
  • 1870 views

I am working on a local service. I want to put in a check for undefined infotable input. The code below fails to save because of the return. Does anyone have any suggestions on how should I can trigger the return of my service if this check fails?

if (typeof newDataInfotable == "undefined"){
    logger.warn("data infotable was empty"); 
    return;
}

    1 reply

    1-Visitor
    April 27, 2015

    if (typeof newDataInfotable == "undefined"){

    logger.warn("data infotable was empty");  
    } else {

    //put all the code here}
    What I do in most cases is creating a flag and checking all conditions like this:


    var valid = true;

    if (typeof newDataInfotable == "undefined"){

    logger.warn("data infotable was empty"); 

    valid = false;
    }


    if ( //another checking ) {

    valid = false;

    }


    if ( //another checking ) {

    valid = false;

    }


    if ( valid ) {

    //here I put my code when all conditions are fulfilled

    }




    1-Visitor
    May 26, 2016

    I've discovered another way with javascript of doing it:

    labelName:

    {

          // -- your code

          break labelName; // -- it will jump until the end of the braquets.

         // -- other conditional code

    }