0

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"); } }); 
6
  • 1
    undefined != identifier Commented Feb 25, 2017 at 11:35
  • var undefined = false; if ( numLikes == undefined) makes no sense... What are you trying to accomplish with this part of the script? Commented Feb 25, 2017 at 11:40
  • Andreas, That makes no sense because it's unofficial, it's an alledgedly working coding trick. i took it from an answer that had about 20 up votes, from a page nearly the same as my question. It's a trick i found from the 2nd/3rd most popular answer for dealing with undefined vars, it had at least 20 votes. Commented Feb 25, 2017 at 14:11
  • Siam, I thought that your code worked at first, however, it selects every instance of the identifier, whether it is an integer or an undefined value, so in effect it doesnt work at all. Commented Feb 25, 2017 at 15:24
  • numLikes will never be undefined nor false. Also you cannot overwrite undefined. Commented Feb 25, 2017 at 17:19

1 Answer 1

1

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

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

5 Comments

numLikes will never be undefined
it doesnt work for this question, I had tried that already because i read 20 answers for coping with undefined values in other pages. nothing works for undefined on the solidzapps website for number of likes.
I can't get the case where 'numLikes' is undefined. Even when no search is performed there are no DOM nodes with selector as "#pageResults li".
Hey thanks, I added an example to the top of the page. I just typed acid jazz downtempo, set it to 50 results, and have two undefined results.
I want to say Thanks a lot! it's awesome, the isNaN version is working thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.