Defining Booleans
Is today a weekday?
Yes ✅
No ❌
Relax Today😴
Do I have work today?
Yes ✅
No ❌
Work 🏢

Introduction to Booleans

In this lesson, we will explore the fundamental concepts of booleans in Java.

The boolean type describes one of two states: ON or OFF, also known as TRUE or FALSE. It controls the flow of code to determine which piece(s) of code to run.

Booleans are all around us! For instance, the header you are seeing with the steps is only shown when the link includes "lessons/". If it is, then show the lesson header, if not then show the regular header.

boolean isLessonPage = URL.includes("lessons/");
if (isLessonPage) { // = if (true)
	page.showLessonHeader();
} else {
	page.showNormalHeader();
}

Here is the actual code that determines when to show the Header (sneak peek):

React.useEffect(() => {
  const handleRouteChange = (url: string) => {
    setIsLessonPage(url.includes('lessons/')
    || url.includes('teach/')
    || url.includes('cocode/'));
  };
  handleRouteChange(pathname);
}, [pathname]);