The Two Move Checkmate in Four
The Two-Move Checkmate
Those who have played serious chess for a while likely have heard of the famous two-move checkmate, also known as Fool's Mate:
This is the shortest achievable checkmate from the standard starting position. It requires the White pieces to move the f pawn (1 or 2 spaces) and g pawn (2 spaces) and the Black pieces to move the e pawn (1 or 2 spaces) to open the diagonal for the Queen to attack.
In practice, this is rarely seen in a real game. In my almost 20 years of playing chess, I have never seen the two move checkmate occur on the board in a real game. Unlike the four-move checkmate (Scholar's Mate), the two-move checkmate is much less common to achieve since the opponent with the White pieces either is aware of it or even if they are not, it is highly unlikely they will play the exact moves that allows the Black pieces to achieve this.
Recently in the 2021 Chess.com Daily Chess Championship Round 1, I played a game that was the closest of all my games to the two-move checkmate. In the game, I played a checkmate very similar in pattern to the two-move checkmate, achieving it in four moves with the White pieces with a bishop sacrifice along the way.
Avoiding the Two-Move Checkmate (and the general pattern)
Because the two-move checkmate requires very specific moves to be played by both players, it's unlikely to slip into the exact checkmate by accident, even for those new to the game.
To avoid this mating pattern in general for either side, one good practice is to have at least one of the f or g pawns unmoved before the king is castled. The reason is either of these pawns in their starting positions will be enough to ward off an attack along the h4-e1 diagonal (or h5-e8 diagonal for the black pieces). In general it is unwise to open up lines to the king early as the lines can be used by opposing pieces to attack the king.
Another technique is to develop the kingside knight to f3 (or f6 for the black pieces) if there is a threat of an attack along the h4-e1 diagonal. The knight will guard the important h4 (or h5 for the black pieces) square, from which the attack is usually executed by the opponent's Queen or Bishop.
Thirdly, as a general practice, it is good to castle the king early, removing the king from the diagonal line of attack into a safer place in the corner behind other pawns.