0

I have this very simple code to check whether the value is null or not but, it is not working and passing through the 'if' condition.

enter image description here

Code:

var existingFilterCriteria = filterCriteriaSectionRow.data('filterapplied');

if (existingFilterCriteria != null && existingFilterCriteria != '' && existingFilterCriteria != 'null');
{
    MappingQueryFilter = existingFilterCriteria;
}

Question:

Am I doing anything wrong here? Is there any special check I have to do for data returned from the 'data' attribute in a DOM element?

5
  • What is the value of filterCriteriaSectionRow.data('filterapplied')? What is the expected output? How do you define "working"? Commented Jun 23, 2015 at 17:33
  • 2
    Also, the code you showed in the screenshot of the code is different than the code you copied and pasted. For example, != and !== are by no means the same thing. Commented Jun 23, 2015 at 17:34
  • 2
    Use or operator than and operator. Commented Jun 23, 2015 at 17:35
  • @JoshBeam, I agree. I was trying different options to capture the null check. Let me update the code. Commented Jun 23, 2015 at 17:38
  • try this way: if(existingFilterCriteria) { .. Commented Jun 23, 2015 at 17:41

1 Answer 1

5

You have a ; at the end of your if statement.

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

5 Comments

Yeah, that's the problem but still it should be or operator than and operator.
@Bhojendra Nepal why? what if the value is '''. He would still go inside when he doesn't want to
NO, both case wouldn't match anytime as null !== ''
@brso05, you care correct. The semicolon (;) was causing the issue. After I removed it, things started to work fine. I don't know how I missed it. Thanks for catching it.
@BhojendraNepal he only wants to execute the block of code if existingFilterCriteria contains something a non null non empty string...

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.