2 answers

The inclusion of JR57243 with BPM 857CF2017.03 resulted in behavior change for reserved properties such as listLength.

Prior to this CF, calling .listLength non a non-list object would return undefined/null without throwing an error. However, starting with CF2017.03 the reserved properties are now strictly enforced.
Therefore calling .listLength on a non-list object now throws an error since you should not be calling this property on a non-list object.

If you are looking for a way to check if an object is a list the following JS would be a better implementation:

*This APAR also results in a behavior change when mapping output variables for a nested service. See this dWAnswers post for more details.

**If you are using the convertTwToJson function from the open-source BPMJSON Helper toolkit then you will have to modify the function to first check if an object is a list before calling .listLength. The current version does not perform this check, and will throw the "property listLength for class xxxx is undefined"
https://developer.ibm.com/bpm/resources/json-helper-toolkit/

Instead of the method convertTwToJSON() of the BPMJSON Helper toolkit you can use a new method that comes with CF2017.03 for the conversion to JSON.
You need to call toJSONString() for an object or a list as documented in the JavaScript API, e.g.

tw.local.variable.toJSONString()

The conversion the other way around works like:

tw.local.variable = JSON.parse(jsonString)

If dates are included in the objects, the following property (introduced with the APARs JR45755 and JR49873) needs to be set to true, e.g. in 100Custom.xml:

If you have larger objects, I would recommend against the above solution which uses describe. That basically converts the entire object to XML just see if the current object you are on is an array. And it will need to do that for every sub-object that's inside. For large nested objects that would take enormous amounts of memory and CPU compared to the listLength check that was there before.

The toJSONString() method listed in the comments should work nicely for converting to JSON. However - it won't help you if you need to convert to a native javascript object instead of JSON and there are a couple differences from the convertTwToJSON method. The dates are formatted differently and null properties get added as null instead of skipped. Not a huge thing, but may require code changes in your projects.