Easiest way to check if string is null or empty

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

    Here is a jsfiddle demonstrating a very easy way of doing this.

    Basicly you simply do this is javascript:

    var email="oranste";
    var password="i";
    
    if(!(email && password)){
        alert("One or both not set");        
    }
    else{
        alert("Both set");   
    }
    

    In coffescript:

    email = "oranste"
    password = "i"
    unless email and password
      alert "One or both not set"
    else
      alert "Both set"
    

    Hope this helps someone :)

提交回复
热议问题