I come from a C# background and need to become more familiar with JS. I’m reading a book and in this example:
var as = document.getElementsByTagName('a');
for(var i=0;i<as.length;i++){
t=as[i].className;
//Check if a link has a class and if the class is the right one
if(t && t.toString().indexOf(popupClass) != -1)
{
//...
}
Part of the if statement doesn’t make sense. What is if(t)? I am used to if statements checking boolean values, but t is a string, right?
The if statement does type coercion.
if (o) block;will only run the block. if
ois “truthy”The following values are falsy:
"", null, undefined, false, 0, NaNThe rest are truthy.
A good article can be found here
More to the point you have lots of dead code.