JavaScript 如此受欢迎的 4 个原因
JavaScript

> 
> JavaScript 之所以能在编程语言中名列前茅，是有充分的理由的。
> 
> 
> 


![](/data/attachment/album/202011/17/102936u1hghm95bbu7xjxg.jpg)


如 GitHub 的 [The State of the Octoverse](https://octoverse.github.com/) 报告的这张图所示，如果按 GitHub 上项目的贡献者数量统计，[JavaScript](https://en.wikipedia.org/wiki/JavaScript) 一直是最受欢迎的编程语言。


![The State of the Octoverse 报告中的热门语言](/data/attachment/album/202011/17/103021ngxojxso2qx8oldj.png "Top Languages from The State of the Octoverse report")


*热门语言，根据《The State of the Octoverse》（©2019，[GitHub Corp](https://octoverse.github.com/)）*


在本系列的 [上一篇](/article-12813-1.html) 中，我们深入了解了 JavaScript 的历史。在这篇文章中，我将分享它如此受欢迎的四个[原因](https://medium.com/paul-heintzelman/so-why-is-javascript-so-popular-f35bd6cfeb39)。


### 1、JavaScript 适合初级、中级和高级开发人员


JavaScript 不需要任何环境设置，只要打开浏览器，比如 Chrome 浏览器，导航到[开发者工具](https://developers.google.com/web/tools/chrome-devtools)，就可以开始编码。编写一个 “Hello World” 的程序，就这么简单：



```
console.log("Hello World");

```

JavaScript 的灵活性最适合中级开发人员。该语言通过让开发人员专注于解决问题来帮助你完成任务。开发者可以混合使用插件和自己的代码片段来让一个应用程序工作。


虽然 JavaScript 比较容易上手，但它也并不是一下子就能掌握的。如果你想达到高级水平，这里有一些你需要了解的概念：


* **JavaScript 的[多范式](https://medium.com/javascript-in-plain-english/what-are-javascript-programming-paradigms-3ef0f576dfdb)特性：** JavaScript 同时支持函数式编程和面向对象编程（OOP）。
* **在 JavaScript 中应用[设计模式](https://addyosmani.com/resources/essentialjsdesignpatterns/book/)：** 模型-视图-\*（[MV\*](https://developpaper.com/javascript-mv-pattern/)）设计模式一直是最流行的模式之一，并促成了[多个现代框架](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel#JavaScript_frameworks)的发展。
* **[带原型链的继承](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain)：** JavaScript 由于其动态的特性，无法实现传统的 Java 基于类的模式下的 OOP。JavaScript 中的 OOP 是通过原型继承模型实现的。
* **[闭包](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures)：** 闭包可以从内部函数中访问外部函数的作用域。
* **<ruby> <a href="https://javascript.info/currying-partials">  柯里化 </a> <rt>  Currying </rt></ruby>：** 柯里化是函数的一种转换，它将函数从 `f(a, b, c)` 的调用形式转换为 `f(a)(b)(c)` 调用形式。
* **[Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) 和 [Observables](https://rxjs-dev.firebaseapp.com/guide/observable)：** 这些可以帮助你处理异步函数。
* **[TypeScript](https://en.wikipedia.org/wiki/TypeScript)：** 在 JavaScript 中添加了静态类型。


### 2、全平台


JavaScript 可以在任何地方运行，包括：


* 手机、平板电脑和笔记本电脑等设备。
* 在客户端和服务器端。


这种在任何地方都能运行的能力使 JavaScript 成为一种通用语言。


### 3、开放标准和社区


[ECMAScript](https://en.wikipedia.org/wiki/ECMAScript) 是 JavaScript 的标准化版本，也是一种开放的标准语言。公司可以使用 ECMAScript 来创建 JavaScript 的实现。根据[维基百科](https://en.wikipedia.org/wiki/List_of_ECMAScript_engines)，“ECMAScript 引擎是执行以 ECMAScript 语言标准编写的源代码（例如，JavaScript）的程序”。最流行的引擎 [V8](https://en.wikipedia.org/wiki/V8_%28JavaScript_engine%29) 和 [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) 是开源项目。


JavaScript 已经存在了 25 年，背后有一个庞大的社区。开发者们简直目不暇接，社区已经构建了如此多的插件和框架，以至于创造了“[框架疲劳](https://teropa.info/blog/2015/07/15/overcoming-javascript-framework-fatigue.html)”这个词。


### 4、现代框架


现代框架如 [React](https://en.wikipedia.org/wiki/React_%28web_framework%29)、[Angular](https://en.wikipedia.org/wiki/Angular_%28web_framework%29) 和 [Vue.js](https://en.wikipedia.org/wiki/Vue.js) 已经稳定下来，并且正在进行优化以获得更好的性能。大多数框架对开发者非常友好，有良好的社区支持。


### 未来


JavaScript 将长期存在。全栈开发和现代前端框架继续帮助 JavaScript 巩固其作为最受欢迎的编程语言之一的地位。


JavaScript 的[下一波](https://medium.com/@rangleio/the-future-of-javascript-in-the-front-end-world-2544c1814e2)可能会将焦点放在。


* **[Deno](https://en.wikipedia.org/wiki/Deno_%28software%29)：** JavaScript 的现代安全运行时。
* **网络组件：** 可重复使用的自定义元素。
* **与 AI 和 ML 的整合：** 像 [Supernova](https://techcrunch.com/2018/03/13/supernova-studio/) 和 [BAYOU](https://futurism.com/military-created-ai-learned-to-program) 这样的项目在将 JavaScript 与人工智能和机器学习整合方面取得了实质性的突破。




---


via: <https://opensource.com/article/20/11/javascript-popular>


作者：[Nimisha Mukherjee](https://opensource.com/users/nimisha) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
As this chart from GitHub's * State of the Octoverse* report shows,

[JavaScript](https://en.wikipedia.org/wiki/JavaScript)has consistently been most popular programming language based on the number of contributors to projects on GitHub.

![Top Languages from The State of the Octoverse report Top Languages from The State of the Octoverse report](https://opensource.com/sites/default/files/uploads/toplanguages-the_state_of_the_octoverse.png)

opensource.com

In the [previous article](https://opensource.com/article/20/10/javascript-part-1) in this series, I dove into the history of JavaScript. In this article, I'll share four of [the reasons](https://medium.com/paul-heintzelman/so-why-is-javascript-so-popular-f35bd6cfeb39) it is so popular.

## 1. JavaScript caters to beginner, intermediate, and advanced developers

JavaScript does not need any environment setup; just open a browser, like Chrome, navigate to [Developer Tools](https://developers.google.com/web/tools/chrome-devtools), and start coding. Writing a "Hello World" program is as simple as:

`console.log("Hello World");`



JavaScript's flexibility is best suited for intermediate developers. The language just helps get things done by letting the developer focus on solving the problem. Developers can use a mix of plugins and their own code snippets to get an application working.

While JavaScript is relatively easy to get started with, it is not straightforward to master. If you want to get to an advanced level, here are some of the concepts you need to know:

**JavaScript's**JavaScript supports both functional programming and object-oriented programming (OOP).[multi-paradigm](https://medium.com/javascript-in-plain-english/what-are-javascript-programming-paradigms-3ef0f576dfdb)nature:**Applying**The model-view-* ([design patterns](https://addyosmani.com/resources/essentialjsdesignpatterns/book/)in JavaScript:[MV*](https://developpaper.com/javascript-mv-pattern/)) design patterns have been among the most popular and have led to the development of[several modern frameworks](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel#JavaScript_frameworks).JavaScript cannot implement OOP in the traditional Java class-based model due to its dynamic nature. OOP in JavaScript is achieved through the prototypal inheritance model.[Inheritance with prototype chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain):A closure gives access to an outer function's scope from an inner function.[Closures](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures):Currying is a transformation of functions that translates a function from callable as f(a, b, c) into callable as f(a)(b)(c).[Currying](https://javascript.info/currying-partials):These help you work with asynchronous functions.[Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)and[Observables](https://rxjs-dev.firebaseapp.com/guide/observable):This adds static typing to JavaScript.[TypeScript](https://en.wikipedia.org/wiki/TypeScript):

## 2. Omni-platform

JavaScript can run everywhere, including:

- Devices like mobiles, tablets, and laptops
- On the client-side as well as the server-side

This ability to run everywhere makes JavaScript a universal language.

## 3. Open standards and community

[ECMAScript](https://en.wikipedia.org/wiki/ECMAScript) is the standardized version of JavaScript as well as an open standard language. Companies can use ECMAScript to create a JavaScript implementation. According to [Wikipedia](https://en.wikipedia.org/wiki/List_of_ECMAScript_engines), "an ECMAScript engine is a program that executes source code written in a version of the ECMAScript language standard, for example, JavaScript." The most popular engines, [V8](https://en.wikipedia.org/wiki/V8_%28JavaScript_engine%29) and [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey), are open source projects.

JavaScript has been around for 25 years and has a vast community behind it. A developer is spoiled for choice. The community has built so many plugins and frameworks that the phrase "[framework fatigue](https://teropa.info/blog/2015/07/15/overcoming-javascript-framework-fatigue.html)" was coined.

## 4. Modern frameworks

Modern frameworks like [React](https://en.wikipedia.org/wiki/React_%28web_framework%29), [Angular](https://en.wikipedia.org/wiki/Angular_%28web_framework%29), and [Vue.js](https://en.wikipedia.org/wiki/Vue.js) have stabilized and are being optimized for better performance. Most frameworks are very developer-friendly with good community support.

## The future

JavaScript is here to stay. Full-stack development and the modern frontend framework continue to help JavaScript cement its position as one of the most popular programming languages.

The [next wave of JavaScript](https://medium.com/@rangleio/the-future-of-javascript-in-the-front-end-world-2544c1814e2) might put the spotlight on:

## 1 Comment