Hello World in Google Apps Script

Hello World in Google Apps Script Featured Image

Welcome back to the Hello World in Every Language series. Once again, I get to chat about a code snippet that was shared by someone in the community, Arun PattniOpens in a new tab.. Thanks to them, we’re able to tackle Hello World in Google Apps Script, a scripting language that first appeared in 2009.

Table of Contents

Google Apps Script Background

According to WikipediaOpens in a new tab., Google Apps Script is a scripting language for the G Suite which includes applications like Gmail, Google Drive, Google Calendar, etc. In other words, we’re dealing with a domain specific language.

In terms of features, Google Apps Script shares a likeness to JavaScript. As a result, the language is relatively easy to learn.

That said, there are some limitations. For instance, each script is executed in the cloud, so their are restrictions such as limiting access to various services.

In addition, working with date/time objects can be challenging as data may cross time zones during execution. As a result, developers have to be very deliberate in their scripts.

Overall, Google Apps Script appears to be a great tool for anyone looking to write add-ons for G Suite applications. Otherwise, you’ll probably never use it.

Hello World in Google Apps Script

At any rate, here’s the implementation of Hello World in Google Apps Script:

function helloWorld() {
  Logger.log("Hello, World!");

Unlike many languages, Google Apps Script code doesn’t need a main function. In fact, all we have to do is define a function. Google handles what we want to do with the script at runtime.

With that in mind, we can see that we’ve defined a helloWorld function with syntax similar to JavaScript. In other words, we have a function definition which encloses a code block with braces.

Inside the code block, we have our typical print call. In this case, we leverage the Logger to do our printing. Then we pass our “Hello, World!” string to the log function, and call it a day.

How to Run the Solution

If we want to run Hello World in Google Apps Script, we actually have to write our scripts using the Apps Script toolOpens in a new tab.. From there, Google has some nice documentationOpens in a new tab. for running them.

Alternatively, we can write scripts locally and upload them to Google Drive. At that point, we can connect the Google Apps Script tool to run our scripts. The link above has directions for that option as well.

If you know of other ways to run Google Apps Script code, let me know in the comments.

Sample Programs in Every Language

And, that’s it for Hello World in Google Apps Script. If you want to contribute to this language, consider forking the Sample Programs repositoryOpens in a new tab..

As always, thanks for stopping by and a special thanks to Arun PattniOpens in a new tab. for their contribution to the series. Every little bit helps!

While I have you here, consider sharing this article. I’m sure your friends will enjoy the series, and they might even want to contribute.

Sample Programs in Every Language (44 Articles)—Series Navigation

For 100 Days of Code, I’ve decided to implement a few sample programs in as many languages as possible. Each implementation details a brief history of the language and a description of the code.

The plan for the series is to explore the major general-purpose language like Java, Python, C, C++, and C#. From there, we’ll take a look at some sample programs in web development languages like Ruby, PHP, and JavaScript. As we continue, we’ll cover proprietary languages like Swift and Objective-C. Eventually, we’ll start to tackle less popular languages like Rust, x86, and Verilog. Finally, we’ll play around with some of the esoteric languages like Brainf*ck and LOLCODE.

Who knows? Maybe the Sample Programs in Every Language series will become so popular it’ll never end. To help this series grow, consider sharing it on social media with your friends. Or, if you have a language you want to see, drop your suggestion in the comments.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts