Skip to content
Related Articles

Related Articles

How to convert CoffeeScript code in JavaScript ?

View Discussion
Improve Article
Save Article
  • Last Updated : 25 May, 2022

CoffeeScript is a lightweight programming language that compiles into JavaScript. It provides simple and easy-to-learn syntax, avoiding the complex syntax of JavaScript. CoffeeScript is influenced by JavaScript, Ruby, YAML, Haskell, Perl, and Python and has influenced MoonScript, LiveScript, and JavaScript.

Example: The below example is demonstrating the conversion of CoffeeScript code into JavaScript code:


# Assignment:
number   = 89
opposite = false
# Functions:
cube = (A) -> a * a * a
# Conditions:
number = -89 if !opposite 

JavaScript is the world’s most popular lightweight, interpreted, compiled programming language. It is also known as a scripting language for web pages. It is well-known for the development of web pages, and many non-browser environments also use it. JavaScript can be used for Client-side developments as well as Server-side development


# Assignment:
number = 89;
opposite = false;
# Functions:
cube = function (A) {
    return a * a * a;
# Conditions:
if (!opposite) {
    number = -89;

Now let us understand the step procedure of how to convert a CoffeeScript code into JavaScript with the example:

Step 1: Write CoffeeScript code and save the file with extension 


// Write coffeeScript program to check whether 
// given number is even or odd 
number = 12
if number % 2 == 0
    console.log "number is even" 
    console.log "number is odd"

Step 2: To run the file, you need to type the following command : 

coffee -c

Step 3: After successful compilation of the above file, the following JavaScript file will generate.


(function () {
    var number;
    number = 12;
    if (number % 2 === 0) {
        console.log("number is even");
    } else {
        console.log("number is odd");


number is even

This is how you can convert CoffeeScript code into JavaScript.

You can refer to any online editor to convert CoffeeScript code into JavaScript.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!