
- 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 - Aliases for logical operators
The following table shows the aliases for some of the logical operators. Suppose X holds true and variable Y holds false.
Operator | Alias | Example |
---|---|---|
&& (Logical AND) | and | X and Y gives you false |
|| (Logical OR) | or | X or Y gives you true |
! (not x) | not | not X gives you false |
Example
The following example demonstrates the use aliases for logical operators in CoffeeScript. Save this code in a file with name logical_aliases.coffee.
a = true b = false console.log "The result of (a and b) is " result = a and b console.log result console.log "The result of (a or b) is " result = a or b console.log result console.log "The result of not(a and b) is " result = not(a and b) console.log result
Open the command prompt and compile the .coffee file as shown below.
c:\> coffee -c logical_aliases.coffee
On compiling, it gives you the following JavaScript.
// Generated by CoffeeScript 1.10.0 (function() { var a, b, result; a = true; b = false; console.log("The result of (a and b) is "); result = a && b; console.log(result); console.log("The result of (a or b) is "); result = a || b; console.log(result); console.log("The result of not(a and 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 logical_aliases.coffee
On executing, the CoffeeScript file produces the following output.
The result of (a and b) is false The result of (a or b) is true The result of not(a and b) is true
coffeescript_operators_and_aliases.htm
Advertisements