Joshua is told that the Book of the Law should not depart from his mouth and that he should meditate on it day and night Joshua 1:8. The stated purpose is to be careful to do what is written in it, leading to success in his way Joshua 1:8.
In Joshua 1:8–9, Joshua is told to keep “this book of the law” constantly in speech and thought, so that he will carefully do everything written in it. The passage connects sustained attention to the law with practical obedience, and then links that obedience with a well-guided and successful course of action. These verses come in the opening commissioning scene of Joshua, right after Moses’ death and just before Israel crosses into the land. The larger unit Joshua 1:1–9 moves from the task (lead the people into the land) to assurances (God’s presence and help) to conditions for wise action (attentiveness to the law).
Joshua 1:8–9 presents written instruction (“this book of the law”) as the central guide for Joshua’s leadership at a risky turning point.
A careful answer keeps the immediate passage, the book's argument, and the whole-Bible storyline together, so the question is answered in context instead of as a detached idea.
Start with Joshua 1:8, then read the surrounding section so the answer stays connected to the passage's flow.
8This book of the law shall not depart out of your mouth, but you shall meditate thereon day and night, that you may observe to do according to all that is written therein: for then you shall make your way prosperous, and then you shall have good success.