How to use recursion techniques in off canvas navigations

I’m new to this forum and hope to learn javascript from everyone in this forum.

I’m trying to create an off canvas navigation. This article provides some good techniques:

I’m trying to understand the recursion techniques in the sidebarEffects.js file in above article:

The function hasParentClass (line 13) and bodyClickFn (line 38) all use recursion techniques.

I understand hasParentClass (line 13) uses recursion to repeatedly look for any element has parent “st-menu” (line 38) - please correct me if I’m wrong.

But for bodyClickFn (line 38), this function already has “resetMenu();” to hide the menu. I’m not quite sure why do we need this line “document.removeEventListener( eventtype, bodyClickFn );”.

Any explanation is helpful. Many thanks!