What is the execution process of this code?

I know that the test event will be triggered after scrolling, but the internal process is not very clear. Why is there a return function in it? Which parameter does arguments represent?

function debounce(func,wait,immediate){
    var timeout;
    return function(){
        var context = this,args = arguments;

        var later = function(){
            timeout = null;
            if(!immediate) func.apply(context,args);
        };
        var callNow = immediate&&!timeout;
        clearTimeout(timeout);
        timeout=setTimeout(later,wait);
        if(callNow) func.apply(context,args);
    };
};

var test = debounce(function(){
  console.log("successful")
},250);

window.addEventListener("scroll",test);

I used debugging tools to debug and found that arguments points to event, please help me tell me how it is executed, thank you!

May.26,2022

1. Because as a detrembling function, how can it be executed multiple times without the return function.
2. what is arguments

The

process is to record a timer (here called timeout ), and if it exists, clear the timer , that is, it will not be repeated for a certain period of time.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3c357-44691.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3c357-44691.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?