You can but to be safe it's better to use a variable inside the function because global variables can change and might alter while the function is running or something like this. You can try it for now but you may come across some bugs in a bigger game.
If the global variable didn't change when you tested it then you must not be calling the function or something else is changing the global variable so it looks like it is unchanged (already the kind of bug I was referring to).