2

console is not included in the list, but is pretty much available to use in any environment.

On a side note, why isn't console capitalized like every other built-in global object like Number or Array?

9
  • 1
    console.spec.whatwg.org says "For historical reasons, console is lowercased."
    – Amadan
    Aug 29, 2018 at 6:00
  • 3
    1) Because it is not mentioned in the spec: ecma-international.org/ecma-262/9.0 . 2) Maybe because it is not a constructor but a "normal" function? Aug 29, 2018 at 6:00
  • 1
    @FelixKling It's not even a function, it's just a normal object (acting as namespace)
    – Amadan
    Aug 29, 2018 at 6:02
  • 1
    @Bamieh: It was an answer to another comment that was changed, saying that it's lowercase console because it's not a constructor function. But since you've drawn my attention to your elaboration, "All methods provided by the whatwg spec implementing the window interface are not capitalized" is not an explanation, since, as I've already had to note above, console is not a method.
    – Amadan
    Aug 29, 2018 at 12:43
  • 1
    @Bamieh: Also, window.console is the namespace they're talking about. It is an object whose sole purpose is to group various console-related methods. They are not two different things, as you imply in 'This note is for the namespace definition using "console" and not "Console", not the exposed api on the window object'.
    – Amadan
    Aug 29, 2018 at 12:46

1 Answer 1

7

ECMA-262 doesn't define console because ECMA-262 has no concept of I/O. Simply each browser implements/injects its own console implementation.

The console object was first introduced by browser debugging tools, Firebug was the first to try to formulate a consistent standard for the console api.

The WHATWG (Web Hypertext Application Technology Working Group) has an early work in progress console spec to define the semantics of the console APIs, in an attempt to create convergence across environments.

console is not included in the list, but is pretty much available to use in any environment.

The console object is somehow consistent between browsers due to the following:

  • Browsers and Node.js all individually follow the WHATWG console spec.

  • Chrome extends WebKit which is also used by Safari.

  • Node.js is built on top of V8, which defines the console API used by node.

Currently many of the console methods are cross-browser compatible, however this was not always the case. Check the compatibility table to see the differences.

Arguably, each console implementation differs based on the environment it is served in, (chips, servers, browsers, etc.). Hence it does not make complete sense to have it standardized in ECMA.

Just like other browser specific APIs, the console is injected to javascript to give developers access to the browser API, such as Node and Document.

Here is a list of the complete web API injected into javascript to be accessible in JS code on the browser.

why isn't console capitalized like every other built-in global object?

All methods provided by the whatwg spec implementing the window interface are not capitalized (Check the window interface), Since non of those methods are constructor functions.

It is also mentioned in the spec that the console is lowercased due to historical reasons. However this note is talking about the namespace definition using "console" instead of "Console" used in the spec and NOT the exposed API.


FUN FACT: I remember the time when the console used to throw an error if the debugger was not opened on IE.

4
  • 1
    Great answer! If I may offer a few corrections: 1) ECMA-262 doesn't define console because ECMA-262 has no concept of I/O. 2) browsers and node all individually follow the whatwg console spec, not by browsers happening to be built on other browsers as you suggest. 3) whatwg console spec is already ratified, so no need to use future tense "will be part of the whatwg spec"
    – snek
    Aug 29, 2018 at 12:49
  • @snek thank you! 1) You are correct, please feel free to update the answer. 2) I referred to this line in the spec "This specification is an early work in progress" But indeed it is part of the spec (updated answer).
    – Bamieh
    Aug 29, 2018 at 12:52
  • 1
    @snek Surely the console implementations of the different environments converged before it became a whatwg standard - either because implementations inherited from each other or because they followed the standard set by the Firebug extension (unfortunately no longer online). Here's a bit of history overview: 2ality.com/2013/10/console-api.html
    – Bergi
    Aug 29, 2018 at 13:08
  • 1
    @Bergi definitely. the clarification i was trying to make is that chrome and safari and node.js etc all have the same console interface today because they all willfully follow the same spec. it isn't just because of historical copycat reasons.
    – snek
    Aug 29, 2018 at 13:23

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.