每個 JavaScript 開發者都應該知道的 33 個概念
簡介
這個儲存庫是為了幫助開發者掌握 JavaScript 概念而建立的。這不是必須的要求,而是未來學習的指南。它基於 Stephen Curtis 撰寫的一篇文章,您可以在這裡閱讀。
社群
歡迎透過添加您自己的總結或評論連結來提交 PR。如果您想將此儲存庫翻譯成您的母語,請隨時進行。
此儲存庫的所有翻譯將列於下方:
- 呼叫堆疊
- 原始型別
- 值型別和參考型別
- 隱含、顯式、名義、結構化和鴨子型別
- == vs === vs typeof
- 函式作用域、區塊作用域和詞法作用域
- 表達式 vs 陳述式
- IIFE、模組和命名空間
- 訊息佇列和事件迴圈
- setTimeout、setInterval 和 requestAnimationFrame
- JavaScript 引擎
- 位元運算子、型別陣列和陣列緩衝區
- DOM 和佈局樹
- 工廠和類別
- this、call、apply 和 bind
- new、建構函式、instanceof 和實例
- 原型繼承和原型鏈
- Object.create 和 Object.assign
- map、reduce、filter
- 純函式、副作用、狀態變異和事件傳播
- 閉包
- 高階函式
- 遞迴
- 集合和產生器
- Promises
- async/await
- 資料結構
- 昂貴的操作和大 O 記號
- 演算法
- 繼承、多型和程式碼重用
- 設計模式
- 部分應用、柯里化、組合和管道
- 乾淨程式碼
1. 呼叫堆疊
呼叫堆疊是 JavaScript 直譯器用來追蹤程式中函式執行的機制。在 JavaScript 中,函式會按照被呼叫的順序執行。呼叫堆疊遵循「後進先出」(LIFO)原則,這意味著最後被推入堆疊的函式會是第一個被執行的。
根據 ECMAScript 規範,呼叫堆疊被定義為執行環境的一部分。每當函式被呼叫時,就會建立一個新的執行環境並放置在堆疊頂端。一旦函式完成,其執行環境就會從堆疊中移除,控制權回到先前的環境。這有助於管理同步程式碼的執行,因為每個函式呼叫必須完成後,下一個才能開始。
參考資料
文章
影片
⬆ 回到目錄
2. 原始型別
根據 ECMAScript 規範,JavaScript 有六種原始資料型別:string、number、bigint、boolean、undefined 和 symbol。這些型別是不可變的,意味著它們的值無法被改變。還有一個特殊的原始型別叫做 null,它代表刻意不存在任何物件值。
原始值是直接指派給變數的,當您操作原始型別時,您是直接操作該值。與物件不同,原始型別沒有屬性或方法,但 JavaScript 會在必要時自動將原始值包裝成對應的物件(例如,在字串上呼叫方法時)。
參考資料
文章
影片
⬆ 回到目錄
3. 值型別和參考型別
根據 ECMAScript 規範,值型別是直接儲存在變數所存取位置的。這些包括 number、string、boolean、undefined、bigint、symbol 和 null 等型別。當您將值型別指派給變數時,儲存的是值本身。
另一方面,參考型別是儲存在堆積中的物件。指派給參考型別的變數實際上儲存的是物件的參考(指標),而不是物件本身。當您將參考型別指派給另一個變數時,兩個變數都參考記憶體中的同一個物件。
文章
影片
⬆ 回到目錄
4. 隱含、顯式、名義、結構化和鴨子型別
ECMAScript 規範將 JavaScript 定義為動態型別語言,這意味著型別與值相關聯而非變數,且型別檢查在執行時發生。JavaScript 管理型別有多種方式:
隱含型別(或型別強制轉換): 這發生在 JavaScript 需要時自動將一種資料型別轉換為另一種時。例如,JavaScript 可能在算術運算期間將字串轉換為數字。雖然這可以簡化某些程式碼,但如果處理不當,也可能導致意外的結果。
顯式型別: 與隱含型別不同,顯式型別涉及使用 Number()、String() 或 Boolean() 等函式手動將值從一種型別轉換為另一種型別。
名義型別(Nominal Typing): JavaScript 原生並不支援名義型別,即明確宣告和檢查型別的方式。然而,TypeScript 作為 JavaScript 的超集,帶來了這個功能來幫助在開發過程中捕獲型別錯誤。
結構型別(Structural Typing): 在這種型別系統中,型別是基於資料的結構或屬性。JavaScript 是一種結構型別語言,其中物件如果具有相同的結構(即相同的屬性和方法集合)就是相容的。
鴨子型別(Duck Typing): 這是一個概念,物件的適用性是由某些屬性和方法的存在來決定,而不是由物件的實際型別決定。JavaScript 大量依賴鴨子型別,其中行為是從物件的屬性推斷出來的,而非其宣告的型別。
文章
影片
書籍
⬆ 回到目錄
5. == vs === vs typeof
根據 ECMAScript 規範,JavaScript 包含嚴格(===)和寬鬆(==)相等運算子,它們在比較值時表現不同。以下是分析:
== (寬鬆相等):此運算子在比較兩個值之前執行型別強制轉換。如果值的型別不同,JavaScript 會嘗試在比較之前將一個或兩個值轉換為共同型別,這可能導致意外的結果。
=== (嚴格相等):此運算子在不進行任何型別強制轉換的情況下比較值和型別。如果兩個值不是相同型別,比較將返回 false。
typeof 運算子:typeof 運算子用於檢查變數的資料型別。雖然它通常是可靠的,但有一些特殊情況,例如 typeof null 返回 “object” 而不是 “null”,這是由於 JavaScript 實作中的長期行為。
文章
影片
⬆ 回到目錄
6. 函式作用域、區塊作用域和詞法作用域
ECMAScript 規範概述了三種主要的作用域類型:
函式作用域:在函式內使用 var 宣告的變數只能在該函式內存取。此作用域將變數隔離,使其無法在宣告的函式外部被存取。
區塊作用域:隨著 ES6 引入,使用 let 和 const 宣告的變數是區塊作用域的。這意味著它們只能在定義它們的特定區塊 {} 內存取,例如在迴圈或條件陳述式內。
詞法作用域:指的是變數存取如何根據變數在程式碼中的實體位置來決定。函式是詞法作用域的,這意味著它們可以存取其父作用域的變數。
書籍
文章
影片
⬆ 回到目錄
7. 表達式 vs 陳述式
根據 ECMAScript 規範,表達式會產生一個值,而陳述式是執行動作的指令,例如變數指派或控制流程。函式宣告會被提升,可以在程式碼中定義之前被呼叫,而函式表達式不會被提升,必須在被呼叫之前定義。
文章
影片
⬆ 回到目錄
8. IIFE、模組和命名空間
隨著 ES6 模組的引入,IIFE 在作用域隔離中的作用已經減少,但它們仍然具有相關性。
參考資料
文章
影片
⬆ 回到目錄
9. 訊息佇列和事件迴圈
事件迴圈是 JavaScript 並行模型的關鍵部分,透過以非同步方式處理任務來確保非阻塞行為。理解它如何與訊息佇列和微任務互動是掌握 JavaScript 行為的關鍵。
文章
影片
⬆ 回到目錄
10. setTimeout、setInterval 和 requestAnimationFrame
文章
影片
⬆ 回到目錄
11. JavaScript 引擎
文章
影片
⬆ 回到目錄
12. 位元運算子、型別陣列和陣列緩衝區
文章
影片
⬆ 回到目錄
13. DOM 和佈局樹
參考資料
書籍
文章
影片
⬆ 回到目錄
14. 工廠和類別
文章
影片
⬆ 回到目錄
15. this、call、apply 和 bind
參考資料
文章
- Grokking call(), apply() and bind() methods in JavaScript — Aniket Kudale
- JavaScript’s Apply, Call, and Bind Methods are Essential for JavaScript Professionals — Richard Bovell
- Javascript: call(), apply() and bind() — Omer Goldberg
- The difference between call / apply / bind — Ivan Sifrim
- What the hack is call, apply, bind in JavaScript — Ritik
- Mastering ‘this’ in JavaScript: Callbacks and bind(), apply(), call() — Michelle Gienow
- JavaScript’s apply, call, and bind explained by hosting a cookout — Kevin Kononenko
- How AND When to use bind, call, and apply in Javascript — Eigen X
- Let me explain to you what is
this
. (Javascript) — Jason Yu
- Understanding the “this” Keyword in JavaScript — Pavan
- How to understand the keyword this and context in JavaScript — Lukas Gisder-Dubé
- What the heck is this in Javascript? — Hridayesh Sharma
- This and Bind In Javascript — Brian Barbour
- 3 Techniques for Maintaining Your Sanity Using “This” in JavaScript — Carl
- Mastering the JavaScript “this” Keyword — Aakash Srivastav
- This binding in JavaScript – 4. New binding — Spyros Argalias
- A quick intro to ‘this’ in JavaScript — Natalie Smith
- A conversation with the ‘this’ keyword in Javascript — Karen Efereyan
- What are call(), apply() and bind() in JavaScript — Amitav Mishra
- Understanding ‘this’ binding in JavaScript — Yasemin Cidem
- Top 7 tricky questions of ‘this’ keyword
影片
- JavaScript call, apply and bind — techsith
- JavaScript Practical Applications of Call, Apply and Bind functions— techsith
- JavaScript (call, bind, apply) — curious aatma
- Understanding Functions and ‘this’ In The World of ES2017 — Bryan Hughes
- bind and this - Object Creation in JavaScript - FunFunFunction
- JS Function Methods call(), apply(), and bind() — Steve Griffith
- call, apply and bind method in JavaScript
- Javascript Interview Questions ( Call, Bind and Apply ) - Polyfills, Output Based, Explicit Binding - Roadside Coder
⬆ 回到目錄
16. new、建構函式、instanceof 和實例
文章
⬆ 回到目錄
17. 原型繼承和原型鏈
參考資料
文章
影片
書籍
⬆ 回到目錄
18. Object.create 和 Object.assign
參考資料
文章
影片
⬆ 回到目錄
19. map、reduce、filter
文章
- JavaScript Functional Programming — map, filter and reduce — Bojan Gvozderac
- Learn map, filter and reduce in Javascript — João Miguel Cunha
- JavaScript’s Map, Reduce, and Filter — Dan Martensen
- How to Use Map, Filter, & Reduce in JavaScript — Peleke Sengstacke
- JavaScript — Learn to Chain Map, Filter, and Reduce — Brandon Morelli
- Javascript data structure with map, reduce, filter and ES6 — Deepak Gupta
- Understanding map, filter and reduce in Javascript — Luuk Gruijs
- Functional Programming in JS: map, filter, reduce (Pt. 5) — Omer Goldberg
- JavaScript: Map, Filter, Reduce — William S. Vincent
- Arrow Functions: Fat and Concise Syntax in JavaScript — Kyle Pennell
- JavaScript: Arrow Functions for Beginners — Brandon Morelli
- When (and why) you should use ES6 arrow functions — and when you shouldn’t — Cynthia Lee
- JavaScript — Learn & Understand Arrow Functions — Brandon Morelli
- (JavaScript )=> Arrow functions — sigu
- Javascript.reduce() — Paul Anderson
- Why you should replace forEach with map and filter in JavaScript — Roope Hakulinen
- Simplify your JavaScript – Use .map(), .reduce(), and .filter() — Etienne Talbot
- JavaScript’s Reduce Method Explained By Going On a Diet — Kevin Kononenko
- Difference between map, filter and reduce in JavaScript — Amirata Khodaparast
- Map⇄Filter⇄Reduce↻ — ashay mandwarya
- Finding Your Way With .map() — Brandon Wozniewicz
- How to write your own map, filter and reduce functions in JavaScript — Hemand Nair
- How to Manipulate Arrays in JavaScript — Bolaji Ayodeji
- How to simplify your codebase with map(), reduce(), and filter() in JavaScript — Alex Permyakov
- .map(), .filter(), and .reduce() — Andy Pickle
- Map/Filter/Reduce Crash Course — Chris Achard
- Map, Filter and Reduce – Animated — JavaScript Teacher
- Map, Filter, Reduce and others Arrays Iterators You Must Know to Become an Algorithms Wizard — Mauro Bono
- How to Use JavaScript’s .map, .filter, and .reduce — Avery Duffin
- Using .map(), .filter() and .reduce() properly — Sasanka Kudagoda
- Mastering the JavaScript Reduce method ✂️ — sanderdebr
- JavaScript Map – How to Use the JS .map() Function (Array Method) — FreeCodeCamp
影片
- Map, Filter and Reduce — Lydia Hallie
- Map, Filter and Reduce - Akshaay Saini
- Functional JavaScript: Map, forEach, Reduce, Filter — Theodore Anderson
- JavaScript Array superpowers: Map, Filter, Reduce (part I) — Michael Rosata
- JavaScript Array superpowers: Map, Filter, Reduce (part 2) — Michael Rosata
- JavaScript Higher Order Functions - Filter, Map, Sort & Reduce — Epicop
- [Array Methods 2/3] .filter + .map + .reduce — CodeWithNick
- Arrow functions in JavaScript - What, Why and How — Fun Fun Function
- Learning Functional Programming with JavaScript — Anjana Vakil - JSUnconf
- Map - Parte 2 JavaScript - Fun Fun Function
- Reduce basics - Part 3 of FP in JavaScript - Fun Fun Function
- Reduce Advanced - Part 4 of FP in JavaScript - Fun Fun Function
-
[reduce Array Method |
JavaScript Tutorial - Florin Pop](https://www.youtube.com/watch?v=IXp06KekEjM) |
-
[map Array Method |
JavaScript Tutorial - Florin Pop](https://www.youtube.com/watch?v=P4RAFdZDn3M) |
-
[Different array methods in 1 minute |
Midudev (Spanish)](https://youtu.be/Ah7-PPjQ5Ls) |
⬆ 回到目錄
20. 純函式、副作用、狀態變異和事件傳播
文章
影片
⬆ 回到目錄
21. 閉包
參考資料
文章
影片
⬆ 回到目錄
22. 高階函式
書籍
文章
影片
⬆ 回到目錄
23. 遞迴
文章
影片
⬆ 回到目錄
24. 集合和產生器
參考資料
文章
影片
⬆ 回到目錄
25. Promises
參考資料
文章
影片
⬆ 回到目錄
26. async/await
參考資料
書籍
文章
影片
⬆ 回到目錄
27. 資料結構
文章
影片
⬆ 回到目錄
28. 昂貴的操作和大 O 記號
文章
影片
⬆ 回到目錄
29. 演算法
文章
影片
⬆ 回到目錄
30. 繼承、多型和程式碼重用
參考資料
文章
影片
⬆ 回到目錄
31. 設計模式
書籍
文章
影片
⬆ 回到目錄
32. 部分應用、柯里化、組合和管道
書籍
文章
影片
⬆ 回到目錄
33. 乾淨程式碼
文章
影片
⬆ 回到目錄
本軟體採用 MIT 授權條款。更多資訊請參見授權條款 ©Leonardo Maldonado.
⬆ 回到目錄
學習愉快! ⭐
如果您覺得這個儲存庫有幫助,請考慮給它一個星星!