JAVASCRIPT
JavaScript is a HIGH-LEVEL PROTOTYPE-BASED OBJECT-ORIENTED MULTI-PARADIGM INTERPRETED OR JUST-IN-TIME COMPILED DYNAMIC SINGLE-THREADED GARBAGE-COLLECTED programming language with FIRST-CLASS FUNCTIONS.
(1) High-level
Any computer program needs resources for example CPU. JavaScript do not have to manage resources at all, because these languages hava so-called abstractions. This makes language easier to learn and to use, but the downside is that programs will never be as fast or as optimized as for example, C programs.
(2)Garbage-collected
An algorithm inside the JavaScript engine which automatically removes old, unused objects from the computer memory, in order not to clog it up with unnecessary stuff so it's a little bit JavaScript has a cleaning guy who cleans our memory from time to time so that we don't hava to do ti manually in our code.
(3)Interpreted or just-in-time complied
Computer's processor only understands zeros and ones. Ultimately, every single program needs to be written in zeros and ones, which is also called machine code. We simply write human-readable JavaScript code, which is an abstraction over machine code but this code eventually needs to be translated to machine code and that step can be either compiling or interpreting.
In JavaScript, this happens inside the JavaScript engine.
(4)multi-paradigm
In programming, a paradigm is an approach and an overall mindset of structuring our code, which will ultimately direct the coding style and technique in a project that uses a certain paradigm.
THERE ARE THREE PARA: (1) Procedural programming
(2)Object-oriented programming(OOP)
(3)Functional programming(FP)
We also can classify PARA as imperative and declarative.
(5)Prototype-based object-oriented
Almost everything in JavaScript is an object except for primitive values such as numbers strings, but arrays are just object, why we can creat an array and then use the push method on ti? for example
const arr = [1, 2, 3];
arr.push(4);
const hasZero = arr.indexOf(0) > -1
it's because of prototypal inheritance.We create arrays from an array blueprint which is like a template and this is called the prototype it contains all the array methods and the arrays that we create in our code then inherit the methods from the blueprint so that we can use them on the arrays.
(6)First-class functions
Functions are siimple treated as variables.
We can pass functions into other functions and we can return functions from functions, this is extremly powerful, because it allows us to use a lot of powerful techniques and also allows for functional-prgramming.
EXAMPLE
const closeModal = () =>{
modal.classList.add('hidden');
overlay.classList.add('hidden');
};
overlay.addEventListener('click',closeModal);
We pass the closeModal into the addEventListener function as if it was just a regular variable.
(7)Dynamic
Dynamic-typed language
let x = 1;
let y = 10;
x = 'TT';
We don't assign data types to variables, they only can be know when JavaScript engine executes our code, and the type of variavles can easily be changed as we reassign variables.
(8)Single-threaded and Non-blocking exent loop
Concurrency model: how the JavaScript engine multiple tasks happening at the same time.
JavaScript runs in one single thread, so it can only do one thing at a time.Therefore we need a way of handing multiple things happening at the same time.
When we hava a long-running task: It would block the single thread. HOWEVER, we want non-blocking behavior.
By using an event loop: tasks long running tasks, executes them in the "background", and puts them in the main thread once they are finished.