How to CoffeeScript on Browser

CoffeeScript is a little language which compiles into JavaScript. CoffeeScript makes it possible to write less code, compared to JavaScript, and the syntax is more clean. it can be used on a node environment or on a browser. This article shows how one can use CoffeeScript on browser

GETTING STARTED

For using coffeescript on an html page, we’ll first need to load the coffeescript core compiler. Should note that the js file meant for the node environment doesn’t work on the browser

where can you get the coffeescript core compiler to use on your browser? link to it is on the coffeescript homepage under the “Installation” section (an image for reference shown below)

After getting the compiler, link to it on your html file like you normally do.

<script src="coffee-script.min.js"></script>

WHERE TO PUT IT

just like JavaScript, you could put your CoffeeScript in a separate file or within the html file (in script tags). The only difference being the type attribute’s value

IN THE SAME HTML ITSELF

<script type="text/coffeescript">
	alert "coffee"
</script>

COFFEE FILES

<script type="text/coffeescript" src="script.coffee"></script>
# the <script.coffee> file
alert "coffee"

You may also like...