You Don't Know JS Yet: Get Started!, First Chapter.

You Don't Know JS Yet: Get Started!, First Chapter.

Chapter 1

Language Creator: Brendan Eich

At first, Netscape named it LiveScript, but when they wanted

to release it, JavaScript got the most votes and became JavaScript.

Because at that time, it was supposed to be pleasant for Java

programmers to use it, and the?word script?was generally popular.

Although there are some similarities between JavaScript and Java

syntax structures, it should not be mistaken. "Java" is to "JavaScript" as

"Ham" is to "Hamster" - Jeremy Keith, 2009.

There is a 50 to 100 member?technical management committee?called TC39

that manages JavaScript. They meet bimonthly and review all the proposals.

They are from a wide range of companies that have invested in the web space,

such as Mozilla, Apple, Google, and more. They work voluntarily.

Any proposal must go through 5 stages to become final and be registered

with ECMA. Anyone interested can participate in the discussions on the proposals, but only members of the?TC39 committee?can vote.

All proposals are published on their GitHub page: github.com/tc39/proposals


The reason why JS behaves differently on different browsers is that browser

engines do not accept some of the changes. In such cases, either TC39 publishes that function under another name that does not cause problems, or sometimes they decide that this change is necessary and do not change their decision.

So how do we know what is JavaScript and what is not?

Appendix B, Additional ECMAScript Features for Web Browsers.

It contains all known differences between JS and what actually

happens on the web.

Not all the code we write is necessarily JavaScript. Some of them, like

alert(), fetch(), getCurrentLocation() and even console.log(), are functions

and?object methods?that follow?JavaScript syntax rules.

When we enter code in a console of Developer Tools, we may encounter

some problems. Because these?Developer Tools?are for developers and their goal is to provide a better experience for programmers.


In general, codes are divided into three categories: Functional,

Object-Oriented and Procedural.

? Procedural: Organizes codes from top to bottom.

? Object-Oriented: Organizes codes by gathering their logic and

information into units called classes.

? Functional: Organizes codes into functions.

Some languages are one-paradigm, like C, which is Procedural, or

C ++ and Java, which are almost completely class-oriented. JavaScript is

multi-paradigm.


The term?Backward Compatibility?means that when something like a JavaScript

function is accepted, it will still be usable in the distant future and will

not become unusable. Although in very rare cases changes have been made by

considering all aspects, JavaScript is generally Backward Compatible.

The term?Forward Compatibility?means that code written with new JavaScript

features will work on older JavaScript engines. JavaScript is not Forward

Compatible.

To solve the?Forward Compatibility problem, Transpiling was introduced. It is a

tool to convert parts of the code that are not compatible with the engine to an

older version, such as Babel, which is a Transpiler.

It is better for programmers to use the latest version of JavaScript.

for instance,

if (something) {

let x = 3;

console.log(x);

} else {

let x = 4;

console.log(x);

}

will be transpiled to:

var x$0, X$1;

if(something){

???????????x$0=3;

???????????console.log(x$0);

}else{

x$1=4;

???????????console.log(x$1);

}


Scripted and interpreted programming languages are executed from top to bottom and line by line. For example, if there is an error on line 5, the program executes from line 1 to line 4, and then when it reaches line 5, we see the error.

while in programming languages that are parsed, the entire code is parsed before anything is executed, and errors are seen there. All languages that are

compiled are parsed. That's why we can say JavaScript is compiled. This

compilation generates a?binary byte code?that is then passed to the JavaScript

virtual machine to execute. JavaScript engines can also apply several

optimizations / processing simultaneously to the generated code, which can again be called "compilation" or "interpretation".

In summary, here's what JavaScript does:

  1. JavaScript code is transpiled by Babel and packed by webpack. It then reaches the JavaScript engine.
  2. The?JavaScript engine?parses the code into an AST.
  3. The engine converts that AST into a kind of?Byte Code, which is then optimized by the JIT Compiler.
  4. Finally, the?JS VM?executes the program.


Web Assemble (WASM) enables code in other languages like C to run on JavaScript engines. But we cannot use JavaScript itself in it.


Using?strict mode?ensures that the code we write has the highest quality and

best performance. It restricts us a bit but it's very good to use it.

use strict;

Everything we write below this is in strict mode.

Of course, ultimately, all code written will become strict mode when

transpiled, even if the?source code?is not strict mode.


End of chapter 1



#KyleSimpson

#YouDontKnowJSYet

要查看或添加评论,请登录

Shole Alirezaei的更多文章

社区洞察

其他会员也浏览了