
- CoffeeScript Tutorial
- CoffeeScript - Home
- CoffeeScript - Overview
- CoffeeScript - Environment
- CoffeeScript - command-line utility
- CoffeeScript - Syntax
- CoffeeScript - Data Types
- CoffeeScript - Variables
- CoffeeScript - Operators and Aliases
- CoffeeScript - Conditionals
- CoffeeScript - Loops
- CoffeeScript - Comprehensions
- CoffeeScript - Functions
- CoffeeScript Object Oriented
- CoffeeScript - Strings
- CoffeeScript - Arrays
- CoffeeScript - Objects
- CoffeeScript - Ranges
- CoffeeScript - Splat
- CoffeeScript - Date
- CoffeeScript - Math
- CoffeeScript - Exception Handling
- CoffeeScript - Regular Expressions
- CoffeeScript - Classes and Inheritance
- CoffeeScript Advanced
- CoffeeScript - Ajax
- CoffeeScript - jQuery
- CoffeeScript - MongoDB
- CoffeeScript - SQLite
- CoffeeScript Useful Resources
- CoffeeScript - Quick Guide
- CoffeeScript - Useful Resources
- CoffeeScript - Discussion
CoffeeScript - unless...else statement
Just like the if else statement, we also have an unless else statement in CoffeeScript. It contains a Boolean expression, an unless block, and an else block. If the given expression is false, the unless block is executed and if it is true, the else block is executed.
Syntax
Given below is the syntax of the unless else statement in CoffeeScript.
unless expression Statement(s) to be executed if the expression is false else Statement(s) to be executed if the expression is true
Flow Diagram

Example
The following example demonstrates the usage of unless-else statement in CoffeeScript. Save this code in a file with the name unless_else_example.coffee
name = "Ramu" score = 60 unless score>=40 console.log "Sorry try again" else console.log "Congratulations you have passed the exam"
Open the command prompt and compile the .coffee file as shown below.
c:\> coffee -c unless_else_example.coffee
On compiling, it gives you the following JavaScript.
// Generated by CoffeeScript 1.10.0 (function() { var name, score; name = "Ramu"; score = 60; if (!(score >= 40)) { console.log("Sorry try again"); } else { console.log("Congratulations you have passed the exam"); } }).call(this);
Now, open the command prompt again and run the CoffeeScript file as shown below.
c:\> coffee unless_else_example.coffee
On executing, the CoffeeScript file produces the following output.
Congratulations you have passed the exam