13

I am checking a value in my controller.Here is my code.

var contents = atob(response.documents);
// I checked the value in contents . it is displaying ""
if(contents === ""){
 // no contents
}

the if condition is retuning false, when the contents has "" and when the contents has data. How to check condition?

1

4 Answers 4

19

Good plain Javascript.

if(!contents){

}
Sign up to request clarification or add additional context in comments.

Comments

11

How about contents.trim().length === 0 ?

Comments

1

Empty string in Javascript is falsey you can use:

if(contents){
  //has content
}else{
 //no content
}

Comments

-1

In javascript "" is false and when you compare it with "", it always gives true.Maybe you have doubled empty string (empty string inside string)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.