Get the App
SLTechnology News&Howtos  ›  Development  › 

What is CoffeeScript?

Shulou Source: shulou.com Published: 2022-06-02 15:43:15 10月01日 Update

The main content of this article is to explain "what is CoffeeScript". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what CoffeeScript is.

CoffeeScript is a translation language for JavaScript, and its founder JeremyAshkenas jokingly calls it the less extravagant little brother of JavaScript. Because CoffeeScript compiles code similar to Ruby syntax into JavaScript, and most of the structures are similar, the difference is that CoffeeScript has a stricter syntax.

How's CoffeeScript?

CoffeeScript, like TypeScript, is a language compiled into JavaScript, and they enhance the expressive power of JavaScript. The so-called compile to JavaScript means that CoffeeScript and TypeScript do not implement their own runtime, they are compiled into equivalent JavaScript code, and then run on JavaScript's interpreter.

The biggest impression of CoffeeScript is its concise expression.

# assignment:

Number=42

Opposite=true

# conditions:

Number=-42ifopposite

# function:

Square= (x)-> xxxx

# Array:

List= [1,2,3,4,5]

# object:

Math=

Root:Math.sqrt

Square:square

Cube: (X)-> x*squarex

# Splats:

Race= (winner,runners...)->

Printwinner,runners

The conciseness of CoffeeScript

CoffeeScript strives for simplicity. Its conciseness is first shown in the removal of some symbols that are only used for grammar control. These include:

Cancel semicolon

Cancel the var statement

Unenclose the inner code in curly braces and use indentation instead

Function calls can omit parentheses without ambiguity

The var declaration involves the complex and complex scope mechanism of JavaScript variables. Let's put this part aside for a while. CoffeeScript simplifies the problem by eliminating the var declaration mechanism altogether. In short, in the CoffeeScript world, variables do not need to be declared in advance, just use them. And there is little danger in this usage.

At this point, I believe you have a deeper understanding of "what CoffeeScript is", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Concise code content translated into syntax functions variables that is parentheses mechanisms simplicity language learning running different complex practical deeper similar extravagant Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MariaDB Docker macOS Redmi