Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is it that Javascript can function differently from browser to browser?

I don't think I need to provide examples because every web developer knows that you need to test your Javascript to make sure it's compatible across different browsers. What I don't get is why. Isn't Javascript Javascript? It'd be like the .NET framework behaving differently on one computer than it does on another. Can anyone shed some light on this, possibly with some source links to go along with their answer?

like image 615
oscilatingcretin Avatar asked Aug 01 '26 14:08

oscilatingcretin


2 Answers

The short answer is every browser writes it's own interpreter for JS

The long answer

To understand why a programming language functions differently you have to understand what happens to a programming language at execution. First there are two types of languages interpreted and compiled. Compiled languages are turned from people readable "code" to machine code before execution and distributed as a binary.

Interpreted languages are compiled on the fly, JS is one of those languages. What does it mean to compile a language on the fly? Well, a computer can understand nothing but 1's and 0's and because of this all higher level languages must be broken down to instructions and then binary. When something is compiled on the fly it compiles a line, then runs it, then compiles the next. (of course there are intricacies but that really is the short of it)

Because JS really has never had a stand alone interpreter until recently, and the browser is JS's main purpose every company had to write their own interpreter that would go into their browser. Microsoft, Mozilla, Netscape... Everyone needed to think of how certain things could be handled and then execute them.

Because of this two things happen first, you are never gonna get the same thing if two people are working on it. Think about when you take an intro to Comp Sci course everyone has to make a calculator app but everyone takes a different approach. That happens all the time with js, and causes some browsers to crawl while others fly.

The second is that companies get set in their ways, they have too much time and energy invested in their interpreter and don't want to start over when modifying works and is cheaper. This means that differences that arose in the past when JS was less used and no where near as critical to web development will remain just because it's really difficult to roll out a whole new version of IE with webkit when it has been centered around it's own interpreter for years.

like image 56
austinbv Avatar answered Aug 04 '26 04:08

austinbv


Read this -> http://www.quirksmode.org/js/intro.html there are lots of version of the JavaScript implementation - all of them have differences.

like image 41
Manse Avatar answered Aug 04 '26 03:08

Manse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!