Skip to content

Basics

What works in the Apps Script V8 runtime

Apps Script runs modern V8 JavaScript on Google servers, without browser DOM globals, Node modules, or background timers.

1 of 5

Modern JavaScript syntax works on Google servers

Apps Script executes server files (.gs) on the V8 JavaScript engine, the same engine inside Chrome and Node.js. Google retired the older Rhino engine in January 2026, so new and maintained projects use V8.

Standard ECMAScript features work directly in Code.gs: const and let, arrow functions, template literals, destructuring, rest and spread syntax, Map, Set, classes, optional chaining (?.), nullish coalescing (??), regular expression named capture groups, and Intl formatters.

Use Map, destructuring, and nullish coalescing in V8
function countRequestsByDepartment() {
  /** @type {Array<[string, string, number | null]>} */
  const rows = [
    ['R-101', 'Finance', 120],
    ['R-102', 'Operations', null],
    ['R-103', 'Finance', 80],
  ];
  /** @type {Map<string, { count: number, total: number }>} */
  const totals = new Map();

  for (const [, department, rawAmount] of rows) {
    const amount = rawAmount ?? 0;
    const current = totals.get(department) ?? { count: 0, total: 0 };
    totals.set(department, {
      count: current.count + 1,
      total: current.total + amount,
    });
  }

  for (const [department, summary] of totals) {
    Logger.log(department + ': ' + summary.count + ' requests, $' + summary.total);
  }
}

2 of 5

What V8 in Apps Script does not include

A JavaScript engine provides language syntax and standard objects such as Array and Math. The host environment provides input, output, networking, and timers. Apps Script supplies Google Workspace globals instead of browser or Node.js APIs.

  • No browser DOM: window, document, localStorage, and navigator do not exist in .gs files. They exist only inside HTML files served through HtmlService.
  • No fetch or URL: use UrlFetchApp.fetch() for HTTP requests instead of browser fetch().
  • No Node.js built-ins: process, Buffer, fs, path, crypto, and require() do not exist. Use Utilities for Base64, digests, HMAC signatures, UUIDs, and ZIP archives.
  • No ES modules in the runtime: import and export statements fail in .gs files. If you write modules locally in TypeScript, compile or strip module syntax before pushing with clasp.
  • No event-loop timers: setTimeout and setInterval are absent. Use Utilities.sleep(milliseconds) for short pauses up to 5 minutes, or ScriptApp time-driven triggers for later runs.

3 of 5

Apps Script service calls block until they finish

Every built-in Apps Script call, such as range.getValues(), GmailApp.sendEmail(), or UrlFetchApp.fetch(), runs synchronously. The next line of your function does not start until Google returns the result.

V8 accepts the async and await keywords because they are part of JavaScript syntax, and Promise callbacks run on the microtask queue. That syntax does not make SpreadsheetApp or UrlFetchApp run in parallel. Worse, if a trigger handler or custom function is marked async and awaits a Promise that has not settled, Apps Script can end the execution before the continuation runs.

When you need parallel HTTP requests in a single run, pass an array of request objects to UrlFetchApp.fetchAll(requests). Google sends those requests concurrently and returns the responses in the same order.

4 of 5

Every .gs file shares one global scope

Splitting code into Config.gs, Helpers.gs, and Main.gs organizes the editor sidebar, not the variable scope. Every top-level declaration in every .gs file shares one project-wide namespace.

Standard function declarations (function buildReport() {}) are hoisted across all files before execution starts, so Main.gs can call a helper defined in Helpers.gs regardless of file order. Top-level const, let, and class declarations run one file at a time in the order shown in the editor sidebar. If FileA.gs reads a top-level const declared in FileB.gs while loading, V8 throws a ReferenceError.

Keep top-level code limited to plain constants, or return configuration objects from functions so file order cannot break initialization.

5 of 5

A trailing underscore hides internal helpers

In Apps Script, ending a function name with an underscore, such as normalizeHeader_(text), marks that function as private to the project.

Functions whose names end in _ do not appear in the editor Run dropdown, cannot be imported as Google Sheets macros, and are hidden from consumers when you publish the project as an Apps Script library. Other files inside the same project can still call them normally.

Remember

The short version

  • Apps Script runs on V8, so const, arrow functions, Map, Set, optional chaining, and ?? all work in .gs files.
  • Browser and Node globals such as window, fetch, URL, Buffer, setTimeout, and import/export do not exist on the server.
  • Built-in service calls are synchronous; use UrlFetchApp.fetchAll() when you need concurrent HTTP requests.
  • All .gs files share one global scope, and top-level const or let values initialize in sidebar file order.
  • End helper names with an underscore (helper_()) to hide them from the Run menu and library consumers.

Keep going

Put it to work

All basics