Easiest way to check if string is null or empty

前端 未结 11 1390
南笙
南笙 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:42

    This is a case where "truthiness" comes in handy. You don't even need to define a function for that:

    test1 = not (email and password)
    

    Why does it work?

    '0'       // true
    '123abc'  // true
    ''        // false
    null      // false
    undefined // false
    

提交回复
热议问题