This is the third day of my participation in the August More text Challenge. For details, see:August is more challenging

“Don’t be afraid, don’t compromise, work hard in the future” – hello! I am little sesame 😄

1. Advantages and disadvantages of JS

In the last article, Sesame student has spent a whole article to elaborate the background of the generation of JS, so the advantages and disadvantages of JS are self-evident.

1. Advantages of JS

  • 1) JS is a lightweight, interpreted or just-in-time programming language with function preference (code is not precompiled).
    • Is based on the browser kernelhtmlScripting languages that add life;
  • 2) weakly typed scripting languages :(languages in which data types can be ignored and a variable can be assigned values of different data types);
    • Because of weak typing, it is more flexible and easier to learn. Developers can pay more attention to logic and don’t have to spend too much time worrying about syntax.
  • 3) Cross-platform features:
    • Supported by most browsers, it runs on multiple platforms (Windows, Linux, Mac, Android, iOS, etc.).
  • 4) Single threaded, event-driven
    • JavaScript responds to users in an event-driven manner. An action that occurs when an action is performed on a Web Page is called an Event. For example, pressing the mouse, moving a window, selecting a menu, and so on can be regarded as events. When an event occurs, it may cause an event response and execute some corresponding scripts. This mechanism is called “event-driven”.
  • 5) Security:
    • JavaScript is a secure language, which does not allow access to the local hard disk, does not allow data to be stored on the server, does not allow network documents to be modified or deleted, only through the browser for information browsing or dynamic interaction. Thus effectively prevent data loss.

2. Disadvantages of JS

After all, the development cycle was only 10 days, a lot of the design was not well thought out, and it was born in the netscape vs. Internet Explorer battle, which was not very friendly to older versions of Internet Explorer.

Above we have listed many advantages of JS, these advantages are also his disadvantages

  • 1) JS only throws errors at runtime (easy to hide security risks)
    • Any spelling mistake, will not prompt error;
    • Running times’ fault, pointing is not necessarily the source of the error;
  • 2) Because it is a weakly typed language, the maintenance cost is relatively large, and it is not suitable for the development of large programs
  • 3) JS has no concept of type, and declared variables are dynamic types. Although flexible and easy to use, it is not easy to manage. For example:
    • As an operator, the plus sign has two meanings. It can represent the sum of numbers and the concatenation of characters to characters.

For detailed Javascript design shortcomings, I recommend you to check out Ruan Yifeng’s 10 Javascript design flaws

The birth of TS

Since JS has so many disadvantages, why not replace it with a new language?

  • This is a problem we explained in the last post, and Microsoft has tried to useJScriptreplaceJS“But eventually gave up under pressure from the standards
  • With Internet Explorer losing market share to Google Chrome, Microsoft built a new Edge browser in 2015 using the open source Chakra JavaScript engine. But by this point, it was clear that Google Chrome, with its Web standards focus and powerful V8 JavaScript engine, had won the browser wars.

  • The browser wars are over, Google has built Chrome, and HTML5 is on the rise. Google has also built a very efficient JavaScript engine, and JavaScript is much more efficient.

  • At that time, many developers had already started building large JavaScript applications for browsers, and were gradually discovering some of the disadvantages of JS in large projects (such as the lack of key features such as modules and classes). Also, there is a lack of a type system for establishing order through rules in procedures.)

We still need to use JS, so what can help us avoid the disadvantages of JS?

  • Before TypeScript came along, Microsoft intended to turn a tool called Script Sharp into a product. But Hejlsberg isn’t sure if those developers would want to write JavaScript code in another language. So he began to think about solving the real problem of JavaScript. The key was to add a type system to the language without affecting the things that made JavaScript so popular.

  • Hejlsberg decided to create an “erasable type system,” a component that makes TypeScript a superset of JavaScript. At compile time, TypeScript removes all types and restores the code back to JavaScript.

In a sense, it’s atype systemExists only during developer programming and disappears at runtime. But when it runs, it gives you nothing but benefits.

TypeScript was originally an internal Microsoft project, called Strada, to improve large JS projects.

  • Development began in 2010,
  • The first open source version was released in October 2012 and continues to iterate

Mind mapping

reference

[1]. The father of TypeScript: JS is not a competitor and has struggled to survive in a Microsoft culture that fears open source