sdfsdf
sdfsdf

Reputation: 5590

JavaScript: Why isn't console considered a standard built-in object?

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?

Upvotes: 2

Views: 736

Answers (1)

Bamieh
Bamieh

Reputation: 10906

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.

Upvotes: 7

Related Questions