The best and easiest way to run and debug JavaScript is using node.js. So the first step is to install the node on you laptop. For Mac, just run:
$ brew install node
After the installation, can check the version:
$ node -v
v17.0.1
$ npm -v
8.1.0
Now you can run the JavaScript just with the cmd:
$ node xxx.js
For IDEA, add the Run/Debug configuration:
And click to run and debug:
Note: It can just run the plain JavaScript as it would not provide the HTML DOM.
Reference: