Chapter 2. Language Basics

JavaScript is the Mozilla-managed version of ECMAScript, and the language of Apps Script is based on JavaScript 1.6, but with some additions from 1.7 and 1.8. The community is looking forward to some of the newer ECMAScript features, but for now we are using a fairly old JavaScript dialect. This book uses Apps Script and JavaScript more or less interchangeably.

There will be some examples in this chapter. If you want to follow along, you’ll find how to use the Apps Script integrated development environment (IDE) in the last section.

Style

Although it’s not mandatory in either language, style is an important way of communicating information about the variables and functions to yourself and others who might read your code.

Hungarian

If you are a traditional VBA developer, you may be familiar with the convention known as Hungarian notation. With this convention, the type of the variable forms part of its name. For example:

VB

Dim strInput As String
Dim intValue As Integer
Dim varOutput As Variant

Nowadays, the use of Hungarian is less popular, even in VBA circles, but nevertheless you’ll find it’s still very much alive and well in much of the VBA code you’ll come across.

I find that its focus on type rather than function distracts from the code objective, and is subject to becoming inaccurate following any refactoring. I never use it, but many others like it. In general, I’ll use the JavaScript convention for naming, which will also make language comparison ...

Get Going GAS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.