Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3940720
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:27:12+00:00 2026-05-20T00:27:12+00:00

I come from a C# background and need to become more familiar with JS.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:27:13+00:00Added an answer on May 20, 2026 at 12:27 am

    The if statement does type coercion.

    if (o) block;

    will only run the block. if o is “truthy”

    The following values are falsy:

    "", null, undefined, false, 0, NaN

    The rest are truthy.

    A good article can be found here

    More to the point you have lots of dead code.

    var as = document.getElementsByTagName('a');
    for(var i=0;i<as.length;i++){
        t=as[i].className;
        // no need to check for whether t exists. No need to cast it to a string
        if(t.indexOf(popupClass) !== -1) // use !== for strict equality
        {
           //...
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from more of an Android development background so apologies if this is
I come from a .NET background and need to do a web project in
I come from a Java background and am getting more into .NET, what are
I come from a procedural programming background, and need some help grasping how methods
I come from a C++ background, so apologies if this is a non-C# way
I come from an Actionscript3 background and this is my first time writing any
I come from a webforms background, and at this point I'm quite frustrated with
I'm sure this is sooo simple but I've come from a c# background where
I'm new to this as I come from C++ and Perl background. Trying to
I come from frontend background, so I apologize if this db question seems dumb.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.