JavaScript
- High-level, Prototype-based / Object-oriented, Multi-paradigm, Interpreted or Just-in-time Compiled, Dynamic, Single-threaded, Garbage-collected, First-class finctions, Event Loop Concurrency Model
High-level
- JS, Python : 메모리 관리가 필요 없음
- 그러므로 C언어처럼 빠르지 않음
Garbage Collection
- automatically removes old, unused memory from the computer memory in order not to clog it up with unnecessary stuff.
- we don't need to clean the memory manually.
Interpreted or just-in-time compiled
- machine code : 0 and 1
- Human-readable code -> JS translates it (compiling and interpreting happens inside JS Engine)
Multi-paradigm
- paradigm : an approach and mindset of structuring code, which will direct your coding style and technique.
- 패러다임의 종류 : Procedural Programming(organizing the code in a linear way with some functions between), Object-oriented programming(OOP), Functional Programming(FP)
- Imperative vs Declarative
- JS does everything. very versatile.
Prototype-based Object oriented
- EX. array : there is prototype of an array and the array we coded inherits methods from prototype and also is built from it. .... (ex. Array.prototype.push .. )
First-class Functions
- In a language with first-class functions, functions are simply treated as variables. We can pass them into other functions, and return them from functions.
const closeModal = () => {
modal.classList.add("hidden");
overlay.classList.add("hidden");
}
overlay.addEventListener("click", closeModal);
// 여기서 closeModal - passing a function into another functions as an argument : First-class Functions
Dynamic
- Dynamically-typed language. EX. let x = 23; x = 'yonneki';
- 데이터 타입을 정하지 않고 적어도 결정되고 그 뒤에 변수를 재할당하면 데이터 타입이 자동적으로 바뀐다. 예를 들어 자바와 같은 언어는 이를 허용하지 않는다.
- 이게 좋은지 나쁜지에 대한 의견은 분분하지만 어쨌든 자바스크립트는 이렇게 작동한다.
Single-threaded
- Concurrency Model : how the JS engine handles multiple tasks happening at the same time.
- We need concurrency model because JS runs in one single thread. so it can do one thing at a time.
- Thread is where our code is actually executed in a machine's processor.
Non-blocking Event Loop
- What if we have long-running tasks like fetching data from a remote server? Sounds like it would block the single-thread. How ever we want non-blocking behavior.
- By using an event loop : takes long running tasks, executes them in the 'background', and puts them back in the main thread once they are finished.
- In a nutshell, JavaScript is non-blocking event loop concurrency model with a single thread.