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.

2.1. Your first 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.

Listing 2.1. The coffee machine

2.2. Simple expressions

2.3. Operators

2.4. Statements

2.5. Strings

2.6. Arrays

2.7. Heres for comments, docs, and regexes

2.8. Putting it together

2.9. Summary

sitemap