Is there a web-specific reason for the design choices behind the JavaScript language?

With the advent of “the web is the platform”, JavaScript is fast becoming the most widely used programming language in the world.

However, many tasks that are easy to accomplish in other modern languages are difficult or puzzling in JavaScript, because the language design is so “unique”:

  • JavaScript has a prototype-based OOP system; most other modern languages have an inheritance-based one
  • JavaScript has such a weird typing system that it doesn’t fall into any of the standard categories (plenty of examples on WTFJS)
  • JavaScript is extremely lenient in how it parses the syntax (semicolons are optional etc.)

From a developer’s point of view, most of these design decisions make developing in JavaScript harder. Conceptually, the JavaScript language seems one step behind Java, and two steps behind Python and Ruby. But since I don’t believe that the people behind JavaScript are striving to create a language that is difficult to use, I can only reason that those design points must have something to do with the intended use of JavaScript as a scripting language for web sites, deeply connected to the DOM.

How (if at all) do these design points cater to the intended use cases of JavaScript? What reasoning is behind those seemingly random design decisions?

7

  1. Prototypical inheritance

    This appears to be because, despite what most claim, JavaScript is not a descendent of mostly Scheme, but Self. Self has prototypes and so does JavaScript.

  2. Implicit Coercions

    Neither Scheme nor Self had the invasive amount of implicit coercions that JavaScript has so we have to guess a little bit on why exactly they exist.

    It’s quite reasonable to suggest that Eich was looking at the web and noticed that everything was/is, a string. It makes some level of sense then to say “Hey I know, let’s save the programmer lots of tedious typing and just implicitly turn strings into whatever we want”.

    Additionally, doing this rather than crashing means that while part of the page might render incorrectly because a string didn’t hold a number, the page didn’t crash. Which is arguably a much better UX. Occasionally doing something, even if wrong, is reassuring to the user.

    Remember that JavaScript was rushed to the market and was frozen prematurely, no one knew how much weird stuff was lurking in JavaScript’s implicit conversions until it was too late. I won’t debate in this answer whether they’re good though 🙂

  3. Syntactic Sugar

    I suspect this has nothing to do with JavaScript being a web language and everything to do with JavaScript trying to be easy to use. Allowing optional semicolons and other syntactic sugar is incredibly common nowadays. I’d say it’s more common to find a language made in the last 10 years that omits semicolons than requires them.

    This is all part of a trend towards JavaScript and other languages trying to optimize programmer time be making common patterns easy to type.

To wrap up, No, Kinda, No.

I think the question should be rewritten along the lines of “how did the strengths/weaknesses of internet/web browsers/etc. influence the design and implementation of Javascript?” — in which case, I will delete my post — because most of the question is irrelevant/wrong/cherry-picked/superficial examples that don’t really indicate anything about Javascript’s design.

By learning more about Javascript — especially using it to implement some applications — you will find out that your points are really just traps for the unwary, but become non-issues for more experienced Javascript developers. Understanding and taking advantage of Javascript’s strengths, including this, lexical scoping, closures, higher-order functions, function literals turns out to be more important than getting tripped up by any of the weaknesses you mentioned. OTOH, an actual problem that must be addressed is the lack of a standard module system.

The only interesting sub-question is:

JavaScript has a prototype-based OOP system; most other modern languages have an inheritance-based one

I suspect this has something to do with memory limitations, but I can’t find a reference for that. In addition, as @jozefg mentioned, there are other languages with prototype systems; it has different strengths/weaknesses than “mainstream” inheritance. Prototype-based object systems have their own rich history that you should learn about before dismissing them as mistakes.


However, many tasks that are easy to accomplish in other modern languages are difficult or puzzling in JavaScript

Pick any language, and pose the reverse question — how many tasks that are easy to accomplish in Javascript are difficult or puzzling in other languages? What does the answer say about those other languages? (IMHO, not much — it’s always easy to cherry-pick examples, but much harder to show how those examples prevent people from getting work done)

JavaScript has such a weird typing system that it doesn’t fall into any of the standard categories (plenty of examples on WTFJS)

What is weird about it? It’s definitely not the only language that’s dynamically-typed; neither is it the only one that allows coercions. Perhaps the number of coercions and some unexpected behavior in certain corner cases are distracting you.

JavaScript is extremely lenient in how it parses the syntax (semicolons are optional etc.)

How so? Do you have any other examples of leniency? FWIW, semicolons are optional sometimes; it’s actually well-specified and therefore not what I would call “lenient”.

If this is a problem for you, use a linter.

From a developer’s point of view, most of these design decisions make developing in JavaScript harder.

How so? Can you provide examples? This is very subjective.

Conceptually, the JavaScript language seems one step behind Java, and two steps behind Python and Ruby.

How so? Can you provide examples? This is very subjective.

What reasoning is behind those seemingly random design decisions?

Why do they seem random?

2

Doug Crockford has answered your question in the video “JavaScript: The Good Parts”:
http://www.youtube.com/watch?v=hQVTIJBZook

Just because JavaScript is different, it doesn’t mean it’s worse. The problems is when you try to make a classical inheritance in JS – but you shouldn’t. Prototypes are quite great once you get to understand it.

BTW: Go (golang) has escaped classical inheritance in favor for embedding. Some people say it’s liberating.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật