Easiest way to check if string is null or empty

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

    Instead of the accepted answer passwordNotEmpty = !!password you can use

    passwordNotEmpty = if password then true else false
    

    It gives the same result (the difference only in syntax).

    In the first column is a value, in the second is the result of if value:

    0 - false
    5 - true
    'string' - true
    '' - false
    [1, 2, 3] - true
    [] - true
    true - true
    false - false
    null - false
    undefined - false
    

提交回复
热议问题