0
var someValue1 = '${requestScope.someValue}';
    var someValue = '${requestScope.someValue}';
    var someValue = '${requestScope.someValue}';
    if(someValue1 !== null && someValue1 !== undefined && someValue1 !== '' && someValue1!=='null'){
        alert('Your New someValue1 = '+someValue1);
    };
    if(someValue !== null && someValue !== undefined && someValue !== '' && someValue!=='null' ){
        alert('Error : ' + someValue +"\nDescription : " + someValue);
    };

i want to execute only one alert box depending on the values but null checking is not working.

My both alert boxes are getting executed and that is my main problem. i cant understand why.

5
  • 1
    possible duplicate of How do I check for null values in javascript? Commented Jul 24, 2015 at 7:42
  • Do you have something processing those '{$requestScope.someValue}' string literals in some way? Because in your code above, you have the actual string '{$requestScope.someValue}'. Commented Jul 24, 2015 at 7:47
  • @SubodhJoshi: No, that matches the title of this question, but not the content. Commented Jul 24, 2015 at 7:48
  • no i dont have anything processing it. Commented Jul 24, 2015 at 7:49
  • @tushargarg: Then that's your problem, it's exactly like var someValue = 'foo';. The value you're checking is the actual string '{$requestScope.someValue}. Commented Jul 24, 2015 at 7:51

1 Answer 1

4

All of your values are strings, because you've put them in quotes:

var someValue1 = '${requestScope.someValue}';
// --------------^-------------------------^

Consequently, they'll never be === null or === undefined. Moreover, unless you have something processing those that you haven't shown, they'll never be === '', either, because they're the literal string {$requestScope.someValue} (exactly like 'foo' is the literal string foo).

If you want to check the value, check the value itself, requestScope.someValue.

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

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.