在if语句中使用函数的返回值

在if语句中使用函数的返回值

问题描述:

希望这里有个简单的问题.

Hopefully a quick question here.

可以在if语句中使用函数的返回值吗?即

Can you use a function's returned value in a if statement? I.e.

function queryThis(request) {

  return false;

}

if(queryThis('foo') != false) { doThat(); }

我敢肯定,这很简单明显,但是我遇到了一些语法错误问题,我无法确定问题所在.

Very simple and obvious I'm sure, but I'm running into a number of problems with syntax errors and I can't identify the problem.

您可以简单地使用

if(queryThis('foo')) { doThat(); }

function queryThis(parameter) {
    // some code
    return true;
}