Use of global variables should be minimized in most cases to promote modularity, maintainability, and to reduce the risk of unintended interactions between functions.
Instead, it's usually better to pass data between functions as arguments or to return data from functions as return values.