On Windows, After Effects uses the V8 open-source JavaScript engine. On macOS, After Effects uses the JavaScriptCore framework. Both of these engines provide a more modern version of JavaScript than available in ExtendScript, which only supports the 3rd Edition of the ECMA-262 Standard.
To choose whether a project uses the JavaScript engine or Legacy ExtendScript, in the Project Settings dialog, click the Expressions tab, and change the Expressions Engine option. Projects saved in previous versions of After Effects default to Legacy ExtendScript.