Why not use the boolean comparison Unit is Dead equal to True/False?
Because that not always tells you if that unit is dead.
The check compares the unit's health to 0:
return GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0
Which means that your unit is dead when his life is below or equal to 0.
However a unit dies when he is falling below the minimum HP threshold, which is 0.415 iirc.
So a unit with 0.3 life is dead and showed his death animation and cannot be controlled any more... however it is NOT dead according to this method.
Another problem is that you are able to raise the HP of any unit including dead units.
This means that when your unit had 0 HP and you increase that hp (no matter if it was intentional, you just did it), that means that this unit is not dead any more... but you still cant control it.
That is why we use this method:
return IsUnitType(u, UNIT_TYPE_DEAD) or GetUnitTypeId(u) == 0
When a unit dies (hp falls below 0.415) his UNIT_TYPE_DEAD is set to true, which causes you to lose control and make it play the death animation.
So when a unit has IsUnitType(u, UNIT_TYPE_DEAD) set to true, that means he is dead.
However there is one problem that when you call that function on a unit that is removed from the game it always returns false.
The problem is that you dont want your effect to happen on non-existing units so you do another check in which case you check if the unit type of the unit is 0.
If it is 0 that means that your unit is removed so you cannot apply effects on it.
However this means that not all checks can be done like this.
Instead, when you want an effect to happen on dead units (example resurrection), you need this check:
return IsUnitType(u, UNIT_TYPE_DEAD) and GetUnitTypeId(u) != 0
But if you want to have an effect to happen on alive units (filtering dead units), you need this check:
return not (IsUnitType(u, UNIT_TYPE_DEAD) or GetUnitTypeId(u) == 0)
I havent really tested out the IsUnitAlive() native but it might work as well.