same API just another scripting language. So yes this should work with JavaScript as well.
An example with executeCommandLine for JavaScript can be found here. You need to replace the argument with the state then.
This describes methods that are available related to items in JavaScript.