title: Understanding the usage of executeAsyncScript in Selenium
body: <p>I am trying to understand the documentation for Selenium's <code>executeAsyncScript</code> here (<a href="https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html" rel="nofollow noreferrer">https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html</a>) , for instance in their first example they have :</p>
  
  <pre><code>  long start = System.currentTimeMillis();
     ((JavascriptExecutor) driver).executeAsyncScript(
         "window.setTimeout(arguments[arguments.length - 1], 500);");
     System.out.println(
         "Elapsed time: " + System.currentTimeMillis() - start);
  </code></pre>
  
  <p>Now as far as I understand, the first argument is supposed to be a script, while the last one is a callback function, but in this example there is no callback, so what is going on here (arguments[] is empty right?).</p>
  
  <p>If I wanted to have a function that returns a promise, and then print the promise, say <code>doSomething().then(function(result) { return result;)});</code> how would this work with the <code>executeAsyncScript</code> function?</p>
  
  <p>Thanks</p>