CoffeeScript | Statements
Last Updated :
28 Apr, 2025
The syntax of CoffeeScript is simpler to JavaScript and can be easily learned if you have knowledge of JavaScript. It avoids the use of semicolons, curly braces, and variable declarations.
CoffeeScript Statements: The statements of CoffeeScript do not end with semicolons (;). In this language, a new line is considered as a separate statement by the CoffeeScript compiler. Let's take an example to understand it.
Example:
javascript
Name = “Geek”
Age = 19
Console.log Name
Console.log Age
Output:
Geek
19
Console.log() is a function that prints the result on the console in JavaScript but in CoffeeScript, we simply use console.log without using any parenthesis. In the same way, two statements can be written in a single line separating with a semicolon as shown below:
Example:
javascript
Name = “Geek” ; Age = 19
Console.log Name
Console.log Age
Output:
Geek
19
CoffeeScript Variables: In CoffeeScript, the use of the var keyword is exempted. The variables are created by assigning values to them. Like in JavaScript, we declare variable using var keyword.
var a = 10
var b = 20
But in case of CoffeeScript, we declare the variable as:
a = 10
b = 20
Parenthesis: While declaring a function in most of the programming languages, we make use of parenthesis to avoid ambiguity and make code readable. But in CoffeeScript, the parenthesis is not used whereas an arrow mark (->) is used instead of parenthesis while creating functions as shown below.
Example:
javascript
Function = > console.log "Hello World"
It is the case sometimes when we need to use parenthesis. For example, while calling such functions as created above to display the result on the console, we call the function as:
Function()
Let’s take another example of Square function that gives the square of a number as a result:
Example:
javascript
Square = (x) -> x*x
Console.log Square 4
Output:
16
Curly Braces: Generally, for the code blocks such as functions, loops, we use curly braces but In CoffeeScript, we don't use curly braces. Instead, the proper indentation should be maintained with whitespaces inside the body. Here is an example of CoffeeScript function, in this, we have used four whitespaces as indentation to separate the statements within the function.
Example:
javascript
Function = ->
Name = "Nimrat"
Console.log "Hello" + Name
Function()
Output:
Hello Nimrat
Comments: In programming languages, comments are used to make code more understandable. The comments in CoffeeScript are similar to that of Ruby language. In CoffeeScript, there are two types of comments as follow:
Similar Reads
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Domain Name System (DNS) DNS is a hierarchical and distributed naming system that translates domain names into IP addresses. When you type a domain name like www.geeksforgeeks.org into your browser, DNS ensures that the request reaches the correct server by resolving the domain to its corresponding IP address.Without DNS, w
8 min read
HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML
14 min read
NodeJS Interview Questions and Answers NodeJS is one of the most popular runtime environments, known for its efficiency, scalability, and ability to handle asynchronous operations. It is built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. It is extensively used by top companies such as LinkedIn, Net
15+ min read
What is DFD(Data Flow Diagram)? Data Flow Diagram is a visual representation of the flow of data within the system. It help to understand the flow of data throughout the system, from input to output, and how it gets transformed along the way. The models enable software engineers, customers, and users to work together effectively d
9 min read
What is an API (Application Programming Interface) In the tech world, APIs (Application Programming Interfaces) are crucial. If you're interested in becoming a web developer or want to understand how websites work, you'll need to familiarize yourself with APIs. Let's break down the concept of an API in simple terms.What is an API?An API is a set of
10 min read