I know that global variables are stored in slots of storage layout. But where are the functions stored?
I would like to know technically why.
Basically, given a function selector, your bytecode knows where the functions are kept and use the selector to know where to jump your code to.
I’m assuming you are referring to one of the four data storing locations: storage, memory, call data, and stack. Function parameters and variables declared inside functions are generally stored in memory data locations (location for value type variables are stored in memory while locations for reference type variables are stored in storage).
Function parameters and variables declared inside functions are stored in memory because they are short-lived and local to the scope of the function.