The name property contains the name of the objects in Illustrator, which is displayed in the Layers panel. To rename a selected object, just use this construction:
selection[0].name = "square";
In Illustrator older than CC 2020 we are in for a surprise, the new name will not appear in the Layers panel until we reset the selection or select another object.
Solution
A quick way to see the new name and keep the object selected is to add an empty path after the name is assigned and remove it immediately.
var tmp = app.selection[0].layer.pathItems.add();
tmp.remove();
If you change the name of an unselected object, you can use another way — after setting the name, change the visibility of the object’s layer.
path.name = "New";
path.layer.visible = false;
path.layer.visible = true;