Skip to content

What is CoffeeScript? What is JavaScript?

DeeDeeG edited this page Apr 20, 2021 · 2 revisions

CoffeeScript is an alternative to JavaScript

So what is JavaScript?

JavaScript is a general-purpose programming language, invented for the web. JavaScript, along with HTML and CSS, are widely considered the three core languages of the web. What sets JavaScript apart from other programming languages, is that it is the only one natively supported by all modern web browsers.

JavaScript makes web pages much more useful and interactive than HTML and CSS alone can be. JavaScript can control web pages, and do math, and all the many things programming languages can do, all in the user's web browser. One of the most basic and important things JavaScript can do is show or hide, even create or destroy parts of the page. For example, when a user clicks "map view" on our restrooms result page, the section of the page with the map in it is shown, and the "list view" part is hidden, all through JavaScript.

refugerestrooms/app/assets/javascripts/views/restrooms/index.js#L11

For more information about JavaScript, here's a guide: JavaScript_basics

Refuge Restrooms uses several JavaScript files. All of them are located here:

refugerestrooms/app/javascript/packs

What is CoffeeScript? (Doing Things CoffeeScript Style)

Using CoffeeScript over JavaScript is mostly a style choice, as both are equally functional. CoffeeScript has its own writing style, but compiles to JavaScript for compatibility with web browsers.

A line of CoffeeScript tends to be shorter and simpler than the same thing written JavaScript.

For examples of CoffeeScript code, see:

Refuge Restrooms uses lots of plain JavaScript files, and it used to have a few CoffeeScript files as well, though those have since been converted to use plain JavaScript.