
- 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
Aliases for comparison operators
Following table shows the aliases for few of the Comparison operators. Suppose A holds 20 and variable B holds 20.
Operator | Alias | Example |
---|---|---|
= = (Equal) | is | A is B gives you true. |
!= = (Not Equal) | isnt | A isnt B gives you false. |
Example
The following code shows how to use aliases for comparison operators in CoffeeScript. Save this code in a file with name comparison_aliases.coffee
a = 10 b = 20 console.log "The result of (a is b) is " result = a is b console.log result console.log "The result of (a isnt b) is " result = a isnt b console.log result
Open the command prompt and compile the comparison_example.coffee file as shown below.
c:/> coffee -c comparison_aliases.coffee
On compiling, it gives you the following JavaScript.
// Generated by CoffeeScript 1.10.0 (function() { var a, b, result; a = 10; b = 20; console.log("The result of (a is b) is "); result = a === b; console.log(result); console.log("The result of (a isnt b) is "); result = a !== b; console.log(result); }).call(this);
Now, open the command prompt again and run the CoffeeScript file as shown below.
c:/> coffee comparison_aliases.coffee
On executing, the CoffeeScript file produces the following output.
The result of (a is b) is false The result of (a isnt b) is true
coffeescript_operators_and_aliases.htm
Advertisements