Golf Code. The difference between two piece of code

Tell us what’s happening:
I wanted to solve this challenge from FCC.

The first time I wrote:

if (par == 1 && strokes == 1 ) {
    return "Hole-in-one!";
 }

and it didn’t work

until I wrote:

if (par && strokes == 1 )
  {
    return "Hole-in-one!";
  }

So I was wondering what’s the difference between these two that the second one works but not the first one?

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/golf-code

Would need to see full code and the parameters you pass to the function for a more complete answer.

But in the first case either par did not equal one, strokes did not equal one, or neither equalled one.

In the second case you, presumably pass in par so that is true and strokes must have been passed in as one so that would be true. But where the confusion might be is that in the second case the code does not check whether par equals one, it checks whether par is defined and checks whether strokes equals one.

Try removing the check for par == 1 when you return "Hole-in-one!.

I don’t see any indication (in the table) that you need that.

As to why it works, that’s because any number that’s not 0 gets coerced to true and none of the tests has a par argument set to 0.