Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Can someone explain this Javascript code?

var renderList = function(data){

list = data == null ? [] : (data instanceof Array ? data : [date]);

};

1 Answer

Relevance
  • 6 years ago

    That defines a function named "renderList" that sets a global variable named "list" to the input value, converted to:

    ...an empty array, if the input is null, or

    ...a reference to the original value if it's an array, or

    ...a an array whose only entry is (date), otherwise.

    It looks like "date" is a typo and that "data" was meant.

    It also looks like the author is new to programming, since the normal thing to do with such a function is to return the array as a function result rather than assigning it to a global variable. Global variables generally cause more problems than they solve.

Still have questions? Get your answers by asking now.