DEV Community

Discussion on: Properly Understanding the DOM

Collapse
 
jayj1324 profile image
Jonathan

"Think of it this way: the JS language is standardised by the ECMAScript specification, that describes the features of the language and the results they should produce. But it's the browser that is responsible for actually implementing that. So when the browser's JavaScript engine was written, it implemented all the individual features of JavaScript i.e. defined a process for turning JavaScript code into binary that the CPU can execute. "

So each browser is responsible for implementing the entire Javascript language, as long as they follow the ECMAScript specification? There's no "Central" implementation of the language (in the way that there is, for example, with C# or .NET...Microsoft itself would provide you with the .NET runtime and C#, although if there is some standard C# follows, anyone else could theoretically implement the language, the way different browsers implement javascript?

Thread Thread
 
eduardonwa profile image
Eduardo Cookie Lifter

Is this the reason why it's oddly unexpected at times? Which browser do you think handles Javascript as "the most optimized" or closer to the "real thing", now im wondering about how important it is for browsers to get certain features of Javascript, I mean for what they're concerned, it should always run in a certain way. I didn't know about this said "implementation"

Thread Thread
 
joshcarvel profile image
Josh Carvel

OK first I just want to correct my previous answer slightly - the Web APIs are provided by a JavaScript Runtime Environment, which works with the JavaScript engine, I should have made that clear. The JavaScript engine is a standalone entity that can be run in a browser or another environment i.e. in NodeJS. But again, the JavaScript Runtime Environment is implemented by the browser so the point still stands.

To answer your follow-up Jonathan, essentially yes, since there is nothing very 'central' about the web. However, it's not really 'each browser', since many browsers including Chrome, Edge and a lot of lesser known browsers use Chromium, with is all the core functionality of Google Chrome, but just missing some surface-level features which other browsers add on. So the main different implementations of JavaScript are the ones in Safari and Firefox.

As for your questions Eduardo, as far as I'm aware these days there aren't really any discrepancies in the results they produce, aside from newer features of JavaScript not being supported in older browsers. I'm not sure what you mean about 'oddly unexpected' results?

In terms of the most optimised one, if you mean fastest, I don't have the knowledge in that area to say, though I would guess V8 as it's very popular and focused on high performance. I'm also not sure what you mean by the 'real thing', since they are all the 'real thing' if they meet the requirements of the ECMAScript spec. The original implementation was Brendan Eich's original build of SpiderMonkey for the Netscape browser, but SpiderMonkey has changed a lot since then.