Conditional Logic/If Statements

In the Use Conditional Logic with If Statements lesson (and subsequent conditional lessons), I am confused as to why it is not required to use an else block to return only the statement in the conditional if block?

function test (myCondition) {
  if (myCondition) {
     return "It was true";
  }
  return "It was false";
}
test(true);
test(false);

Under test(true), why wouldn’t the function return both “It was true” and “It was false”? Why isn’t the second statement returned since it is not contained within an else block, which would serve to determine whether or not it executes?

Does this have to do specifically with the way return works?

thanks

The function stops once the first return statement is encountered. You ‘return’ from the function to the place where it was called.

Thanks! Didn’t see that noted in prior lessons.

1 Like