Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I comment in CoffeeScript? "/* this */" doesn't work

People also ask

How do you comment in CoffeeScript?

Single-line Comments Whenever we want to comment a single line in CoffeeScript, we just need to place a hash tag before it as shown below. Every single line that follows a hash tag (#) is considered as a comment by the CoffeeScript compiler and it compiles the rest of the code in the given file except the comments.

Is CoffeeScript better than JavaScript?

"Easy to read", "Faster to write" and "Syntactic sugar" are the key factors why developers consider CoffeeScript; whereas "Can be used on frontend/backend", "It's everywhere" and "Lots of great frameworks" are the primary reasons why JavaScript is favored.


Use a single # sign

# like this

One character seems pretty minimal ;)

Also:

###
This block comment (useful for ©-Copyright info) also gets 
passed on to the browsers HTML /* like this! */
###

The main way to comment is sh/Perl/Ruby/... style # comments:

# This comment goes to the end of the line
# and it won't appear in the "compiled"
# JavaScript version.

You use the block style ### comments when you want a comment to appear in the JavaScript version:

Sometimes you'd like to pass a block comment through to the generated JavaScript. For example, when you need to embed a licensing header at the top of a file. Block comments, which mirror the syntax for heredocs, are preserved in the generated code.

So if you start with

###
PancakeParser is Public Domain
###

then you'd get this JavaScript comment in the generated JavaScript:

/*
PancakeParser is Public Domain
*/

Beware of ###! If you use ### to separate sections of code (as I do) it's awfully surprising when that code stops working as a result.