Lagging object renaming
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 have the object remain selected is to re-open the Layers panel after renaming it.
app.executeMenuCommand("AdobeLayerPalette1");
redraw();
app.executeMenuCommand("AdobeLayerPalette1");
And these lines can be wrapped in a function to be called quickly, as I did in my RenameItems script.
selection[0].name = "square";
reopenLayersPanel();function reopenLayersPanel() {
app.executeMenuCommand("AdobeLayerPalette1");
redraw();
app.executeMenuCommand("AdobeLayerPalette1");
}
