What Item’s state? Or are you trying to use the event Object?
Which version of JS?
UI or file based?
Assuming JS Scripting and not Nashorn, to get the state of an Item you need to use the Item.
console.info("The state of MyItem = " + items.MyItem.state);
console.info("The numeric state of MyNumericItem = " +items.MyNumberItem.numericState);
console.info("The quantity state of MyUoMItem = " + items.MyUoMItem.quantityState);
If you are working with the event it differs depending on whether you are in the UI or files. In the UI we get the raw event Object meaning everything in it is a Java Object. Usually you’ll need to convert that data to a String.
console.info("The new state of the triggering Item is " + event.itemState.toString());
console.info("Window open status = " + event.itemState.toString() == "CLOSED");
Ah, sorry. I forgot to post the line for the item state. I’m using the JavaScript in a rule that I created through the UI (openHAB 4.3). I have added that in the original post.