How does JavascriptExecutor work?

I’ve been trying to figure this out for almost a month. I understand that JavascriptExecutor handles executing Javascript. My question is, how does the programmer know what code to pass into the arguments? I’ve been given many solutions for problems I have that work, but it doesn’t matter because I’d have no idea how to get there myself. For example, I received a temporary fix for scrolling:

HashMap scrollObject = new HashMap();
JavascriptExecutor js = (JavascriptExecutor) driver;
String elementId = listElement.getId();

scrollObject.put("text", elementName);
scrollObject.put("element", elementId);

try {
    js.executeScript("mobile: scrollTo", scrollObject);
} catch (WebDriverException e1) ....

There are a few hardcoded Strings being passed in. This example isn’t too bad, but there are a lot of cases I’ve seen with many more Strings. As a programmer, how am I supposed to know what those arguments should be? I know it’s Javascript, but what are the different mobile interactions that are possible? I’ve looked for documentation on JavascriptExecutor but I haven’t been able to find anything. Has anyone else been able to experience more success with this?

I’m sorry if this is a dumb question. Thanks so much!