The bidding tells the tale
Assume you’re East, defending against four hearts reached in the manner shown.
Partner leads a diamond, which you win with the ace, and you return a diamond to partner’s king. Partner continues with the jack, and declarer ruffs.
South leads a low heart to dummy’s jack, and it is at this point that the outcome hangs in the balance. If you take the ace, declarer makes the contract; if you duck, he goes down one.
Let’s say you win the jack with the ace, as most players would do. If you return a diamond, declarer ruffs in dummy and scores the rest of the tricks; if you return anything else, declarer likewise takes the rest.
Now let’s assume you duck the jack of hearts, as you should. What can South then do to make the contract? If he leads another trump, you win with the ace and return your last diamond. If declarer ruffs, he will only have one trump left to West’s two and must go down one. If South discards on the fourth diamond, he goes down that much sooner.
How can you tell that ducking the jack of hearts is the right play? Well, you can’t be certain it will beat the contract, but all the evidence points in that direction.
The main clue lies in the bidding. South is unlikely to have six hearts, because he would be more inclined to rebid a six-card major suit at his second turn than name a minor suit.
Once you credit South with only five hearts — which means West has four — you are sure to beat the contract by refusing to win the first heart.