Exodus 34:28 And he was there with the LORD forty days and forty nights; he did neither eat bread, nor drink water. And he wrote upon the tables the words of the covenant, the ten commandments.
The Bible mentioned nothing about whether Joshua participated in the fasting or not. Exodus 34:28 however specifically mentioned that "he (Moses) was there with the LORD forty days and forty nights;...
Jesus spent this period of fasting in order to prepare Himself for His earthly ministry which was about to begin. It also prepared Him for the time of temptation by the devil in the wilderness.