开发者

how to compare a fbjs variable with fbjs undefined?

i have an alert in fbjs which returns undefined but when i am comparing a fbjs variable with underined it does not work...

var params = document.get开发者_运维技巧ElementById('ques_form').serialize();
    user_answer = params.radio;
    if(user_answer=="undefined")
    {
        alert("please select any option");
        return false;
    }


if(user_answer == undefined)

or more correctly:

if(user_answer === undefined)

undefined is a "special" value in javascript, not the string with value "undefined". When you compare to "undefined" you are comparing if that variable is a string with the text "undefined" instead of checking for the special undefined value in javascript.

Learn: http://www.w3schools.com/jsref/jsref_undefined.asp http://javascript.about.com/od/reference/g/sundefined.htm


I have found the solution of the problem as

if(first === undefined)   
   alert('First is undefined'); 
else   
   alert('First is defined');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜