I've got this line of code:
console.log "source = #{@source.alignment} unit = #{unit.alignment}: " + (@source.alignment is not unit.alignment)
This is printing this out to the console:
source = good unit = bad: false
Why is it printing "false"? Shouldn't it be printing "true"? Logically, good "is not" bad.
This
console.log "source = #{@source.alignment} unit = #{unit.alignment}: " + (@source.alignment != unit.alignment)
prints
source = good unit = bad: true
as expected.
What's the difference? When should I use is not
?
Easy Maintenance and Readability: It becomes easy to maintain programs written in CoffeeScript.It provides the concept of aliases for mostly operators that makes the code more readable.
With the rise of ES6/7 and TypeScript, it seemed like CoffeeScript would become obsolete. But it's not. CoffeeScript was one of the pioneers of the compile-to-JavaScript concept. In fact, some of things you now see in the modern JavaScript appeared in the first version of CoffeeScript some 8 years ago.
As of today, January 2020, CoffeeScript is completely dead on the market (though the GitHub repository is still kind of alive).
It's an operator precedence issue:
a is not b => a is (not b)
That means that this compiles to the next js:
a === !b
In your case, b is unit.alignment, and as that var exists and its value is not falsy, !unit.alignment returns false
To solve your problem, check out isnt
operator in Coffeescript docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With