The JS engine PAM 4.x uses does not support trim(). If you attempt to use it in a javascript code in a PAM Run Javascript Operator, it will result in an error similar to this:
--TypeError: Cannot find function trim. (#16).
The alternative is to use this instead:
.replace(/^\s+|\s+$/gm,'')
For example:
var trimmedTitle = Process.theTitle.replace(/^\s+|\s+$/gm,'');