title: Is there any way to execute javascript functions from java code
body: <p>I am trying to execute a javascript function from java code.</p>
  
  <p>I used JavascriptExecutor from selenium package.</p>
  
  <p>I tried below code</p>
  
  <pre><code>  JavascriptExecutor js;
    js.executeScript("let time;");
    js.executeScript("time = 2;");
    js.executeScript("function f(){console.log(time);}");
    js.executeScript("f()");
  </code></pre>
  
  <p>This is output</p>
  
  <pre><code>Exception in thread "Thread 0" 
  org.openqa.selenium.JavascriptException: javascript error: f is not defined
  </code></pre>
  
  <p>Is there any way to execute the above script from java code? is it possible?</p>