O'Reilly logo

Going GAS by Bruce Mcpherson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required