如果功能:多个必需条件-继续或停止节点继续该功能

时间:2019-02-26 16:50:16

标签: javascript node.js if-statement

在继续执行下面的代码之前,我希望对两种情况进行初步检查。如果没有返回匹配项,我希望Node.js停止任何进一步的处理。不确定是应该将我的主要代码包装在if函数中,还是将其留在代码标题中进行检查。

myValue = 500;
nameLow = "lato";
customerValue = 450;

// Initial check
if (nameLow == 'georgia' && myValue >= customervalue) {
    // Continue executing the code within or other code outside of if function
} else {
    // make Node.js stop executing and close
}

// Main code below (only executed when both conditions match

我不确定在这些情况下是否使用return,continue,break和exitprocess()

还有,如何用三元语句更好地做到这一点?

1 个答案:

答案 0 :(得分:0)

如果补码为真,则退出(process.exit):

if ( nameLow != 'georgia' || myValue < customervalue ) {
    process.exit(1);
}

// Main code below (only executed if nameLow == 'georgia' && myValue >= customervalue)
相关问题