In computer history, one can compare the revolutionary practicality of the industrial period’s assembly line with that of assembly language. The sequential list of instructions (for-loops, while-loops, if-statements), called imperative programming, served as a recipe-like format, but it doesn’t have room for abstracting code for humans (in other words, very literal instructions). It also can run into trouble when executing multiple instructions using the same memory; if there are “too many cooks in the kitchen,” unintended interpretations produce alternate outcomes (or side effects).
By leveraging modern JS, one can lean on functional programming, which bases its logic in evaluating statements as mathematical functions. This way, each function has its own purpose, which reduces hidden dependencies; allows parallelization without tasks “stepping on each other’s toes;” and locks memory to ensure there are no overwrites.
Modern JS’s explicit expressions reduce complexity, making it easier to write and maintain (read) scripts. Two of many favorites are:
Arrow functions: a function is passed as an argument to another function as data, in one line, using an arrow icon =>
Spread operator: inserts the values of an array using 3 dots ...
I recommend two great resources by Google Developer Experts (GDEs):
A summary of JS features with examples by Ben Collins.
A list of free JS learning sites by Amit Agarwal.
Whether it’s physics simulations, invoice trends, ETL (extract, transform, load), or linear regression-based processes, using “map,” “filter,”, and “reduce”with arrow functions is powerful and clear. The runtime also provides a faster CPU computation for such mathematically intensive activities, and a better logs experience.
JS modules, which help import functionality declared in one file into another, are not available at this time. However, if you are looking to leverage modern features like this along with TypeScript, coding in your favorite IDE, or using third party JS libraries like Tensorflow (machine learning), Sequelize (database connector), or GPU Accelerated JavaScript (GPU processing) with the ease of Apps Script’s built-in Google services, you can use CLASP (Command Line Apps Script) in a Node.js environment.
If you’re using scripts that employ the older runtime, review these incompatibility tips—unless you wish to opt out from migrating to the new version. It’s exciting to see what the community can build with the new capabilities modern JS unlocks, especially those who work with Google Sheets and data processing use cases.