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 6569775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:40:26+00:00 2026-05-25T14:40:26+00:00

Something wierd is happening in my javascript and i dont understand it. Can anyone

  • 0

Something wierd is happening in my javascript and i dont understand it. Can anyone explain?

var adsl2pSpeed = '9500 - 12500';

        alert(adsl2pSpeed);

        if (!adsl2pSpeed) {
            alert(adsl2pSpeed);
            var adsl2pSpeed = 'Unknown';
        }


        var speed = document.getElementById("PredictedSpeed");
        speed.innerHTML = adsl2pSpeed + " b/s";

This alerts “Undefined” twice and sets the innerhtml to be “Unknown”. If I comment out the if statment it alerts ‘9500 – 12500’ and sets the innerHTML to be ‘9500 – 12500’. Whats happening? Is the string is being cast as an object so it becomes null?

EDIT : I am actually registing the adsl2pSpeed as a startup script not in the function. I moved it up for clarity but possibly that is the problem?

  • 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-25T14:40:27+00:00Added an answer on May 25, 2026 at 2:40 pm

    Speculation:

    The indented code is in a function.

       if (!adsl2pSpeed) {
            alert(adsl2pSpeed);
            var adsl2pSpeed = 'Unknown';
        }
    

    You are in that function declaring a local variable, which masks the global variable, so it looks “undefined”.

    Try to remove the var to avoid making a new variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got something weird happening here and I can't understand why, on my php
Can anyone suggest a Javascript IDE that will help me with debugging, for example
Something that has always bugged me is how unpredictable the setTimeout() method in Javascript
Something weird is happening to my views all of a sudden (resizing a UITableView
Had something weird start happening to me today. I have an asp.net mvc app
Something really weird is happening: when I call foo(100*1.0f), somewhere along the line that
Lately something weird has been happening to my projects in xcode: I've been trying
Something really weird is happening, it works when I document.write() outside the window.onload =
Something pretty weird is happening with my app: I have the following property in
Something really weird is happening to my Rails app. For some strange reason, jQuery

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.