In AppleScript, you can do:
do shell script "echo 'I am (G)root'" with administrator privileges
Sorry. Anyway, a shell script can be run in JXA like this:
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("echo I am not root :(");
However, there doesn't seem to be an equivalent of with administrator privileges
in JXA. Is there one that I'm missing, or how else should I do it? And don't tell me to use sudo. It won't work.