Why Am I Getting "42" in the Console?


Please see screenshot below; I don’t know why I’m getting “42” – it’s not like I’d asked The Great Chrome Console for the Answer to the Ultimate Question of Life, the Universe, and Everything!

It just started doing this, and even though I’ve reset the console, it’s still doing this, returning extra values from my code, not stopping program execution where it should but an extra iteration later!!!

What’s going on???

Do Pros Work Better at Night?

That is not your program, but the console echoing the last value of the last variable accesed. It can be ignored.

Pay particular note to the directron the line prompt is pointing… To the left, as if to say this is not user inpiut.


Well, what you say there seems to only apply to the second image, where the number 333 is repeated.

But in the first image, it’s not “echoing” the number 41 by outputting 42 afterwards!

And this just started happening…why??? I swear it’s never happened before!!


Its console behavior. If you don’t want it to display, increment the variable before logging instead of after.


Well, yes, but why?? And remember, it’s not done this before – so why’s it doing it now??? There was a Chrome update recently; could that have something to do with it? But why would this sort of console behavior be desirable to implement (if it is indeed new behavior)??

But why would the console – what’s the logic, the sense, in – outputting something that hasn’t been instructed in the program to output??

I’m just trying to understand the reasoning here behind printing out an extra value. And, IIRC, t’s new behavior, too!


You’re wasting your time fretting over something that has no value or importance. Move on.


I don’t see how it’s a waste of time to understand the console and its behavior. If you’ll recall, I’ve said before in another thread how I hate working in the browser console for various reasons and this is one of them – weird behavior that make me wonder if my code is wrong…


There is ample documentation on Google and elsewhere. You are wasting time that would be better spent learning actual code and eventually come to grips with the nuances of the console. Besides, all production code is written for the DOM, not the console. Move on.


I don’t agree. I really don’t think anything’s ever a “waste” of time – and especially in my case, I’ve given myself up to two years to really grok this thing, this web development and programming in general and even computing overall…assuming I am logical, and that computers are, too, I’d like to know why my expectations are not met with respect to browser console behavior. It could point to some underlying heretofore unknown assumption of mine – and that would be a great benefit!

I see it as like so-called imaginary/impossible numbers…mathematicians were puzzled by them for literally hundreds of years before they could finally be applied to something in the real world, thus birthing all of modern electronics!

I’ll ask elsewhere, though (that’s the great thing about having an “omnivorous diet” – though conventional wisdom would normally advise that this is a waste, too); thanks! :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.