donjon
donjon

Reputation: 49

A Boolean function returning a value

Well, I am studying some code and wonder about this function, I know it is a boolean, but I have this before and wonder exactly how this syntax works. Is it supposed to ask if a wall exist or not exist and return true?

hasVisited(): boolean {
    return (
      !this.northWall || !this.eastWall || !this.westWall || !this.southWall
    );
  }

Upvotes: 2

Views: 68

Answers (1)

Avin Kavish
Avin Kavish

Reputation: 8937

This translates into return true if northWall is not truthy or if eastWall is not truthy or if westWall is not truthy or if southWall is not truthy, else return false.

Which translates into return true if northWall is falsy or if eastWall is falsy or if westWall is falsy or if southWall is falsy, else return false.

Which translates into return true if any of the (north|south|east|west)Walls are falsy, else return false.

Upvotes: 2

Related Questions