Features of JavaScript
JS has many features which make it more interesting and the main idea of this blog is to make you aware of what exactly is JS capable of and to witness the key core parts of JS.
JavaScript has the following features
- High Level
- Any programing language that runs on the system needs the hardware RAM/Processor etc.
- For ex. in the C language, developers manage the resources and handle the exception with the help of try-catch block, whereas in JS, Python we don't have to worry about it.
- We don't have to manage the resources here Abstraction takes care of this task and managing resources is been handled automatically.
- But the -ve part is our code won't be as fast as C language code i.e fast and efficient.
- Garbage Collection
- JS Engine Automatically removes all the old, unused objects, from the computer memory.
- Hence we do not have to clean our code manually.
- Interpreted or Just-in-time Compiled
- As Processors only understand 0's and 1's binary, ultimately every single program must be written in 0's and 1's (i.e Machine code)
- Hence we do not have to clean our code manually, i.e abstraction over machine code.
- As code needs to translate into machine code this can be done via compiling and interpreting.
- This is necessary because no one writes the machine code.
- In our case, JS Engine will do this for us.
- Hence JS is a Just-in-time compiled language.
- Multi-Paradigm
- This makes JS more famous as in programming, the paradigm is an approach that will ultimately direct the coding style and technique.
- Procedural Programming, Object-Oriented Programming (OPP's), Functional Programming.
- Paradigm can be imperative and declarative, JS can do all this which makes it flexible, versatile we can use/do whatever paradigm we want as per our requirement.
- Prototype Base Object-oriented Approach
- Almost everything in JS is an Object except the primitive data type.
- The reason we can create the array and use the push() and pop() method on them is because of prototype inheritance, basically, we create an array from the array blueprint which is called a prototype, and use the methods accordingly.
- First Class Function
- The First Class function is simply treated as variables, we can pass them to other functions and return them from functions.
- This allows JS to support functional programming as well.
- Dynamic
- Dynamically typed, as we don't assign the data type to the variable, they only become known when only when JS Engine executes the code. Ex. let x =2; x= "Morshwar" the datatype changes when the values assigned to variable change.
- Single-Threaded and Non-Blocking Event Loop
- JS Engine Handles Multiple tasks, which happen at the same time.
- The thread is like a set of instructions, that is executed by the processor.
- The thread is where the actual code (Source code is executed.) is in the machine processor.
- For long/time-consuming tasks like fetching data from the remote server the single thread may block, but the non-blocking behavior can be achieved with the help of the event loop.
- Event loop takes a long-running task, executes them in the "Background" and puts them back in the main thread once they are completed.
Thanks,
Morehswar P
Comments
Post a Comment