JS understanding the return value of form validation

Hi,
To avoid submitting a form, the JavaScript function (see below) must return false.
Why doesn't it work like this? (see below) The return value must be set to the anonymous function. Thank you!

 document.getElementById("myform").onsubmit = function() {
                  validate();
              };
         
             function validate () {
          
                 var element = document.getElementById("error_div");...
Code (JavaScript):

JS understanding the return value of form validation