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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:19:26+00:00 2026-05-31T12:19:26+00:00

I was using console.log() in some JavaScript I wrote and an error of: console

  • 0

I was using console.log() in some JavaScript I wrote and an error of: console is not defined was thrown in Internet Explorer (worked fine in other browsers).

I have replaced it with:

if (console) console.log("...");

If console is undefined, I would expect the condition to evaluate as false. Ergo, the statement console.log wouldn’t be executed and shouldn’t throw an error.

Instead, an error of: console is not defined at character 4 is thrown.

Is this a IE bug? Or is that “if” condition really illegal? It seems absurd because if if (console) is illegal, then if (console==undefined) should be illegal too.

How are you supposed to check for undefined variables?

  • 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-31T12:19:27+00:00Added an answer on May 31, 2026 at 12:19 pm

    If console itself doesn’t exist at all, it throws an error because you’re accessing an undefined variable. Just like if(abc) {} throws an error.

    Since console resides in window, and window does always exist, this should work:

    if(window.console) ...
    

    Basically, accessing an property that doesn’t exist is free and doesn’t throw an error (it just evaluates to undefined, failing the if condition). However, it is illegal to access an undeclared variable.

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

Sidebar

Related Questions

I want to log to the console when I'm using un-minimized JavaScript files. Comments
I'm using Firebug and have some statements like: console.log(...); in my page. In IE8
I am using log4net to log to the console, and the %date conversionPattern value
I have a little c# console program that outputs some text using Console.WriteLine. I
I'm starting to write some unit test for my javascript code using qunit and
I have a javascript object which has some defined variables and attaches some event
I want to break my string using javascript which is fetching some data from
I am not some one who has done alot in javascript. My background is
I'm using plain old JavaScript (no jQuery or other). I have an HTML5 app
I'm using Uploadify to handle uploads in my CakePHP app. Some uploads work fine

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.