Use the Finder to act on a path, via JXA For a specific example, here’s how to change the name of a specific file via the Finder, in AppleScript:
tell application &quot;Finder&quot; to set name of (POSIX file &quot;/some/file/path&quot; as alias) to &quot;new name&quot;

And here’s how to change the name of the selected file via the Finder, in JavaScript for Automation (JXA):
Application(&quot;Finder&quot;).selection()[0].name = &quot;new name&quot;

How can one do the last line, but acting on a specific given path rather than being limited to the selection? It’s important to use the Finder, because it allows (via the same mechanism) to do more than change the name (like set a comment).
It's quite odd that Finder would expose no method of converting a Path to a Finder file object, yet one doesn't appear to exist. Instead, it seems (per this question) that System Events' aliases property is the only way to convert a path string to a Finder object, like so:
file = Application('System Events').aliases['/some/file/path']
console.log(file.name()) // --&gt; 'path'
file.name = 'newname'

Finder does allow you to manually drill down through the file hierarchy (see this answer), but it's a pain:
file = Application('Finder').startupDisk.folders['some'].folders['file'].documentFiles['path']
console.log(file.name()) // --&gt; 'path'
file.name = 'newname'

However, only some of the attributes these objects are supposed to expose are actually working for me on Big Sur. (Reading and writing comments, for instance, does not seem to work.) If you need reliable and robust Finder scripting, JXA simply may not be the way to go.