Can anyone help me figure out how this code works

Hello,

<script>
            const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]');
            
            checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck));
            let inBetween = false;
            let lastChecked;
            function handleCheck(e) {
                if(e.shiftKey && this.checked) {
                    checkboxes.forEach(checkbox => {
                        // console.log(checkbox);
                        if(checkbox === this || checkbox === lastChecked) {
                            inBetween = !inBetween;
                            // console.log('checking in between');
                        }
                        if(inBetween) {
                            checkbox.checked = true;
                        }
                    });
                }
                lastChecked = this;
                
                
                
            }
        </script>

Code above is supposed to checkbox everything in between two checked items if the shiftkey is held down. I’m having trouble understanding this part

 if(checkbox === this || checkbox === lastChecked) {
                            inBetween = !inBetween;
                            // console.log('checking in between');
                        }

Is this simply just making all the inputs that are in between ‘this’ and ‘lastChecked’ true?