The origins of the 15, 30, and 40 scores are believed to be medieval French. It is possible that a clock face was used on court, with a quarter move of the hand to indicate a score of 15, 30, and 45. When the hand moved to 60, the game was over. However, in order to ensure that the game could not be won by a one-point difference in players' scores, the idea of "deuce" was introduced. To make the score stay within the "60" ticks on the clock face, the 45 was changed to 40.
Therefore, if both players have 40, the first player to score receives ten and that moves the clock to 50. If the player scores a second time before the opponent is able to score, they are awarded another ten and the clock moves to 60. The 60 signifies the end of the game. However, if a player fails to score twice in a row, then the clock would move back to 40 to establish another "deuce".
Simple