Easiest way to check if string is null or empty

前端 未结 11 1216
南笙
南笙 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 13:07

    I'm pretty sure @thejh 's answer was good enough to check empty string BUT, I think we frequently need to check that 'Does it exist?' and then we need to check 'Is it empty? include string, array and object'

    This is the shorten way for CoffeeScript to do this.

    tmp? and !!tmp and !!Object.keys(tmp).length
    

    If we keep this question order, that would be checked by this order 1. does it exist? 2. not empty string? 3. not empty object?

    so there wasn't any problems for all variable even in the case of not existed.

提交回复
热议问题