The number, 40, has a special significance in the scriptures. "When we see the number forty used to denote time in the Bible, we are being told that something extraordinary and definitive is happening."
(Catholic Answers)
Jesus goes through a transformation of sorts in the desert. It was the definitive moment of his transition from carpenter to teacher, prophet, king. His time in the desert must have been a transforming time, a time where he laid hold of his mission, came to understand more clearly his role in God's plan of redemption. One might argue that being divine, he perhaps knew far earlier where his path would lead, but he still embraced this time of transformation, praying, fasting, and facing Satan!