You Don’t Know JS Yet (book series) - 2nd Edition
全文阅读地址From https://github.com/getify/You-Dont-Know-JS
我的GitHub文件: https://github.com/Li-YangZhong/Kyle_Simpson_You_Don-t_Know_JS_Yet_-Get_Started.git
But let me be clear: I don’t think it’s possible to ever fully know JS. That’s not an achievement to be obtained, but a goal to strive after. You don’t finish knowing everything about JS, you just keep learning more and more as you spend more time with the language. And the deeper you go, the more you revisit what you knew before, and you re-learn it from that more experienced perspective.
I encourage you to adopt a mindset around JavaScript, and indeed all of software development, that you will never fully have mastered it, but that you can and should keep working to get closer to that end, a journey that will stretch for the entirety of your software development career, and beyond.
From https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/preface.md
It is not my intention that YDKJSY be read straight through. The material in these books is dense, because JavaScript is powerful, sophisticated, and in parts rather complex. Nobody can really hope to download all this information to their brains in a single pass and retain any significant amount of it. That’s unreasonable, and it’s foolish to try.
From https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/preface.md
So, do your future self a favor and dig into this book and unlock the knowledge within. These solid foundations will serve you better than any framework ever will; those come and go but we’ll still be writing JavaScript itself for decades to come. Keep an open mind and challenge your preconceived notions.
Don’t buy the lie that you should only learn and use a small collection of good parts while avoiding all the bad stuff. Don’t buy the “X is the new Y” snake oil, that some new feature of the language instantly relegates all usage of a previous feature as obsolete and ignorant. Don’t listen when someone says your code isn’t “modern” because it isn’t yet using a stage-0 feature that was only proposed a few weeks ago!
Every part of JS is useful. Some parts are more useful than others. Some parts require you to be more careful and intentional.
The primary point of the title “You Don’t Know JS Yet” is to point out that most JS developers don’t take the time to really understand how the code that they write works. They know that it works—that it produces a desired outcome. But they either don’t understand exactly how, or worse, they have an inaccurate mental model for the how that falters on closer scrutiny.
In particular, Chapter 4 identifies three main pillars around which the JS language is organized: scope/closures, prototypes/objects, and types/coercion. JS is a broad and sophisticated language, with many features and capabilities. But all of JS is founded on these three foundational pillars.
Further distancing the language from the Oracle-owned trademark, the official name of the language specified by TC39 and formalized by the ECMA standards body is ECMAScript. And indeed, since 2016, the official language name has also been suffixed by the revision year; as of this writing, that’s ECMAScript 2019, or otherwise abbreviated ES2019.
In other words, the JavaScript/JS that runs in your browser or in Node.js, is an implementation of the ES2019 standard.
One of the most foundational principles that guides JavaScript is preservation of backwards compatibility.
Backwards compatibility means that once something is accepted as valid JS, there will not be a future change to the language that causes that code to become invalid JS. Code written in 1995—however primitive or limited it may have been!—should still work today. As TC39 members often proclaim, “we don’t break the web!”
The idea is that JS developers can write code with confidence that their code won’t stop working unpredictably because a browser update is released. This makes the decision to choose JS for a program a more wise and safe investment, for years into the future.
Always write code using the most appropriate features to communicate its ideas and intent effectively. In general, this means using the most recent stable JS version. Avoid negatively impacting the code’s readability by trying to manually adjust for the syntax/API gaps. That’s what tools are for!
JS source code is parsed before it is executed.
What does the name pragma mean?
In plain English, pragmatic is an adjective that means sensible and practical. In programming, pragma refers to: The code that consists of useful information on how a compiler or interpreter or assembler should process the program. pragma does not contribute anything to the programming language itself.*
Strict mode is switched on per file with a special pragma (nothing allowed before it except comments/whitespace):
"use strict";
Strict mode can alternatively be turned on per-function scope, with exactly the same rules about its surroundings:
function someOperations() {
"use strict";
}
Interestingly, if a file has strict mode turned on, the function-level strict mode pragmas are disallowed. So you have to pick one or the other.
ES6 modules assume strict mode, so all code in such files is automatically defaulted to strict mode.
Further reading on strict mode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
JS is a compiled language, meaning the tools (including the JS engine) process and verify a program (reporting any errors!) before it executes.
In JS, each standalone file is its own separate program. The reason this matters is primarily around error handling. Since JS treats files as programs, one file may fail (during parse/compile or execution) and that will not necessarily prevent the next file from being processed.
Strings are ordered collections of characters, usually used to represent words and sentences.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
Always keep looking for better ways to use what JS gives us to author more readable code.
From https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/get-started/ch4.md