Easiest way to check if string is null or empty

前端 未结 11 1392
南笙
南笙 2021-01-30 12:30

I\'ve got this code that checks for the empty or null string. It\'s working in testing.

eitherStringEmpty= (email, password) ->
  emailEmpty = not email? or          


        
11条回答
  •  梦谈多话
    2021-01-30 12:46

    I think the question mark is the easiest way to call a function on a thing if the thing exists.

    for example

    car = {
      tires: 4,
      color: 'blue' 
    }
    

    you want to get the color, but only if the car exists...

    coffeescript:

     car?.color
    

    translates to javascript:

    if (car != null) {
      car.color;
    }
    

    it is called the existential operator http://coffeescript.org/documentation/docs/grammar.html#section-63

提交回复
热议问题