Cover by Michael Erasmus

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

A few other things CoffeeScript fixes

JavaScript has lots of other small annoyances that CoffeeScript makes nicer. Let's have a look at some of these.

Reserved words and object syntax

Often in JavaScript, you will need to make use of a reserved word, or a keyword that is used by JavaScript. This often happens with keys for literal objects as data in JavaScript, like class or for, which you then need to enclose in quotes. CoffeeScript will automatically quote reserved words for you, and generally you don't even need to worry about it.

CoffeeScript

JavaScript

tag = 
  type: 'label' 
  name: 'nameLabel'
  for: 'name'
  class: 'label'
var tag;

tag = {
  type: 'label',
  name: 'nameLabel',
  "for": 'name',
  "class": 'label'
};

Notice that we don't need the braces ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required