Be sure to look at the docs for the add-on. It comes with helper libraries (openhab-js) out of the box which does a good job of normalizing all the interactions with OH so that you are working with ECMAScript Objects instead of Java Objects, side stepping a lot of type errors.
It also works significantly differently from JSR223 ECMAScript 5.1 and its Helper Libraries.
I posted a bunch of examples at Some JS Scripting UI Rules Examples.
Also don’t miss that Blockly is now pretty complete when it comes to openHAB support so if a graphical representation of rules is more your speed there isn’t too much you can’t do in Blockly now.
Also look at the rule templates in the Marketplace. These can save you from having to write any code at all in a number of circumstances.