0
function expect(argument) {
   this.eat(argument) || this.undefined();
}

Can someone please help me explain how this code works... the question is focused on this.eat(argument) || this.undefined();. I am guessing that one of those methods would run? and if it is, how do I tell which would run

Davy
  • 58
  • 6
  • 1
    The first (from left) would run. If it doesn't return truthy value, then the second would run. – IT goldman Jul 04 '22 at 17:20
  • Also see the [logical OR operator (`||`) documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR). – D M Jul 04 '22 at 17:22
  • [Logical OR (`||`) operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR) – jsejcksn Jul 04 '22 at 17:22

1 Answers1

0

Or Condition || will return the first true value.

if this.eat(argument) return true or any value which can be converted to true value, So the this.undefined() function will not execute.

If not it will execute.

Mina
  • 14,386
  • 3
  • 13
  • 26