user3187254
user3187254

Reputation: 155

How to do "if undefined" in coffeescript?

How would I get this in CoffeeScript? This is the JS that I am trying to get :

if (value === undefined) {
  return model.get('isCompleted');
} 

Basically, When I am trying this :

if value is undefined
  model.get 'isCompleted'

I am getting this in the JS :

if (value === void 0) {
  model.get('isCompleted');
}

Is there no way to display "undefined" without :

if value is `undefined`

I somehow don't want to use ``.

Upvotes: 1

Views: 1124

Answers (1)

aknuds1
aknuds1

Reputation: 67987

In case you're not aware of the CoffeeScript existential operator, that makes it real easy to check whether a variable is defined (i.e. it's not undefined or null). If it doesn't matter to you whether value is null or undefined, I'd use that. Use it like so:

if !value?
  model.get 'isCompleted'

Upvotes: 3

Related Questions