The SUMIF family has more members that work the same way:
AVERAGEIF(range, criteria, [average_range]) averages the matching rows (same shape as SUMIF).
AVERAGEIFS(average_range, criteria_range1, criteria1, ...) takes several conditions, with the range to average first.
MAXIFS(max_range, criteria_range1, criteria1, ...) and MINIFS(...) return the largest or smallest matching value. They always put the value range first, even with one condition.
When nothing matches, AVERAGEIF has nothing to divide by and shows #DIV/0!, while MAXIFS and MINIFS show 0. Wrap the formula in IFERROR when a blank group is normal.