Chapter 2. Simplified syntax
This chapter covers
- Basic syntax and structure
- Expressions and operators
- An introduction to strings, arrays, objects, and functions
- How to run CoffeeScript programs
Before going to a country where you don’t speak the language, you might spend some time listening to the language to get a feel for it or maybe learn some essential canned phrases to help you get around. Think of CoffeeScript in the same way. As you’re immersed in the syntax of CoffeeScript, you’ll start to build your understanding.
In this chapter, you’ll learn about expressions, operators, and statements, as well as how they work in CoffeeScript and how they’re related to the JavaScript equivalents. You’ll explore fundamental building blocks of CoffeeScript programs with strings, arrays, comments, and regular expressions. You’ll begin with a program.
Imagine a small program that controls a coffee machine (called the Barista). This coffee machine serves different styles of coffee, some with milk and some without, but it doesn’t serve any coffee styles containing milk after midday. Now imagine you find an existing implementation of this CoffeeScript program, as shown in the following listing.