DEV Community

Maksim
Maksim

Posted on • Originally published at maksimrv.Medium on

JavaScript in IDE scripting console

Official script example written in JavaScript

function main() {
  let sum = 0;
  let arr = "35907 77134 453661 175096 23673 29350".split(" ");
  arr.forEach((it) => sum += it.length);

  com.intellij.openapi.ui.Messages.showInfoMessage((sum / arr.length).toString(), "test");
}

main();
Enter fullscreen mode Exit fullscreen mode

IDEA uses GraalJS to run the script. So you can use interop between JavaScript and Java to access Java objects.

JavaScript runtime also has a global variable IDE which reference an instance of com.intellij.ide.script.IDE

IDE.print("Hello World!")
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay