bandybabboon
bandybabboon

Reputation: 2346

undefined var can't be detected in Chrome console?

I have read two full threads on this topic and tried all available syntaxes liste from both of them, and the variable is still undetected.

var undefined = false;
if ( numLikes == undefined)

It's on this website: http://www.solidzapps.com/

If you use this script on the page, you will be able to find undefined likes, on many results:

$("#pageResults li").each(function (){

    var viewsText = $(this).find(".duration-viewCount").text();
    var numViews = +viewsText.match(/\|\s([^ ]+)/)[1].replace(/,/g, "");

    var likesText = $(this).find(".likes").text();
    var numLikes = +likesText.match("^([^ ]+)")[1].replace(/,/g, "");

    //i think numlikes * 80 > numViews is what you're looking for, change that if not
    if (numLikes < 18 || numLikes * (25 + Math.min(15,numLikes/5)) + Math.min(30,numLikes/18) < numViews)
    {   
        $(this).css("height", "0"); 
    }
    var undefined = false;
    if ( numLikes == undefined)
    {   
        $(this).css("height", "0"); 
    }


});

Upvotes: 0

Views: 93

Answers (1)

sanket
sanket

Reputation: 664

In the example you have provided, numLikes comes out to be 'NaN' attributed to this line in your code var numLikes = +likesText.match("^([^ ]+)")[1].replace(/,/g, "");

Try this:

if(isNaN(numLikes)) {
//do Something
}

or

if(!numLikes) {
// do Something
}

My previous answer didn't work because typeof NaN is number not undefined

Upvotes: 1

Related Questions