What is JavaScript ?
JavaScript is a high-level prototype-based object oriented Multiparadigm, interpreted or just in time compilated dynamic, single Treaded, garbage collected programming language with first-class functions and a non-blocking event loop concurrency module.
🤯Don't Worry Let's break above definition into points.👇
- High-level
- Garbage-Collection
- Interpreted or just in time compiled
- Multi-paradigm
- Prototype-based object-oriented
- First class functions
- Dynamic
- Single-Threaded
- Non-blocking event loop
🌟Now Let's discuss each point in detail.
1. JavaScript is High-Level
🟡Every program that runs on our computer needs some hardware resources such as memory and the cpu to do its work.
🟡There are low level languages like C where we have to manually manage these resources.
On the other side we have high level languages like python and JavaScript where we do not have to manage resources at all.
🟡 Because these languages have so called abstractions that take all of the work away from us.
2. JavaScript has Garbage-Collection
🟡 It is basically an algorithm inside the JavaScript engine that removes old, unused objects from the computer memory
🟡 JavaScript cleans our memory from time to time so that we don't have to do it manually in our code
3. JavaScript is interpreted or Just-in-time compiled
🟡 Computer processor ultimately understands 0 or 1 every single program needs to be written in binary language which is also called machine code.
🟡 That is not practical to right that's why we write human-readable code.
Like JavaScript 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.
🟡 Above step is necessary in every single programming language.
🟡 Because no one write machine code manually. IN case of JavaScript This happens inside the JavaScript engine.
4. JavaScript is Multi-paradigm language
🟡 In programming a paradigm is an approach overall mindset of structuring our code. Which will ultimately direct the coding style and technique in a project that uses a certain paradigm.
🟡 Some popular programming paradigm are:-
- Procedural Programming
- Object-oriented programming (OOP)
- Functional Programming
5. JavaScript has prototype-based, object-oriented approach.
🟡 All most everything in JavaScript is an object except of primitive values.
🟡 But arrays, for example are just object.
🟡 Now, have you ever wondered why we can create an array and then use the push method on it
🟡 It's because of "prototypal inheritance". Basically we create arrays from an array blueprint which is like template and this is called the prototype.
👉 I will create a separate thread 🧵 on prototypal inheritance.
6. JavaScript is a language with first class function
🟡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.
🟡Which means functions are treated as regular variables
🟡So, we can pass functions into other functions and we can even return functions from functions.
7. JavaScript is Dynamic
🟡JavaScript is a dynamic language which means dynamically-typed language
🟡In JavaScript we don't assign data types to variables, instead they only become known when the JavaScript engine executes our code.
8. JavaScript is Single-Threaded
🟡 Before know what is single threaded we need to know about the "Concurrency Model"
🟡 Well "Concurrency Model" is a fancy term that means how the JavaScript engine handles multiple tasks happening at the same time.
🟡 JavaScript itself runs in one single-thread which means it can only do on thing at a time and therefore we need a way of handling multiple things at the same time.
🟡By the way in computing a thread is like a set of instructions that is executed in computer's CPU
🟡 So basically, the thread is where our code is actually executed in a machine's processor.
🟡But what if there is a long running task like fetching data from a remote server.
🟡Well it sounds like that would block the single thread where the code is running right.
🟡 But we don't want that. what we want is
🌟 Non-blocking behavior and how do we achieve that. Well by using a so-called event loop. The event loop takes long-running tasks, executes in the background and put's them back in the main thread
🟡 This is in a nutshell JavaScript's non-blocking event loop concurrency model with a single thread
Top comments (0)