In this particular video, let's have a look at features of JavaScript or characteristics of JavaScript.
If I ask you to explain what is JavaScript, we can do so in so many ways.
So let us learn more about JavaScript.
Well, one point about JavaScript is that JavaScript is a single threaded language for each point that
we are going to raise.
We are going to explain it in detail.
So don't worry as you move on, we are going to take them and dive in and explain more about each point.
The second point about JavaScript is that it is a dynamically typed language and it is also an object
oriented programming language.
Again, it is called a garbage collector.
Next is it is a client site programming language.
Next point, it is also a server side programming language.
Next is it is a non blockchain programming language.
And lastly, it is a high level programming language with JavaScript.
We have all these characteristics that define the language.
So let's have a look and take them one by one.
Let's start with JavaScript is a single threaded language.
What does it mean?
This means that JavaScript execute code line by line.
This is because it is using one thread.
Then you may be thinking that well, if JavaScript execute code line by line, then it can affect performance.
Right.
But the answer is no.
And I'll prove to you as we move on.
So with this one, let's get back to visual, see the code and see whether JavaScript run code line
by line.
So back to my Visual Studio code, I have one a HTML and one JavaScript file inside my HTML.
I have only each one and have connected my JavaScript here and inside my JavaScript there is nothing
inside.
So let's see if JavaScript runs code line by line.
So let's comment here and say this is for single.
Third grade.
So here we go.
So let's declare a variable, say my name and is equal to John.
And after that, let's declare age.
Let's say the age variable here is 30, and then let's also declare a function called display.
Cars, display name and every function here and let's say, just console.log.
Let's say my name inside that, my name above.
And after that I also have a function that says Say hello.
So const say hello.
Now when I use arrow function also.
And there you go.
Just say console.log.
Let's say hello.
Great.
So let's call this function, these two functions.
Okay.
So the first function is called display name.
The second function is also say say hello.
Great.
So now before I save this, let's open our console and there you go, let's refresh it.
So when I save it, have a look.
We see that indeed it is running line by line.
When you call this function on line number 13, it comes before line number 14, which says say hello
and remember that console.log is also a function.
So if I bring console that log here, let's say I'm called when I save it.
Let's see the order.
Say hello, will run first, then console.log and then display name.
Have a look when I save it.
And indeed the order is as what you see inside the console.
That is why we see is that JavaScript is a single threaded.
It is waiting for this one to finish running before it goes here and then it goes here.
As we move on, we learn more about how these things happen.
That is one point about JavaScript as a single threaded programming language.
The next point is that JavaScript is dynamically typed language.
What does it mean?
This means that the type of a variable can be changed during the program execution.
What does it mean?
Well, there is a debate about this particular point, that JavaScript must be a strict type programming
language, not dynamically type language.
So what actually is this dynamically typed language?
Well, let's have a look.
So back to visual, see the code here, let's have a comment says dynamically typed language or type
for short.
So let's declare a variable, say full name.
Which is equal to John Doe, for example.
And then let's say the age also is equal to or equal to 28 for this, let's age equal to 28, I think
I have eight being declared.
So let me comment.
This one's out here and now here we have two variables full name and age.
For this we have a variable called full name which holds a string of John Doe and age holds a value
28, which is a number when we say dynamically type language.
Well, we need to specify that for this particular variable.
Indeed, it's supposed to be a string always.
So if you try to update this particular variable, I can change the data type to a boolean or to a number
or whatever.
So let's try to console.log the full name for the meantime and see what we did in the console.
Now.
Indeed, I see John Doe, but I can override this one and change this one to even a boolean or whatever.
So let's update the variable here.
So a full name.
Now I will change this one to, let's say, true.
If I save it.
You can see that I have changed the the full name to true even though at first it was a string, but
now it's a boolean and it works.
That is why we say that JavaScript is dynamically typed.
Language.
Well, it means there are no restrictions on the type of data that can be stored in a variable.
We can store any type of data in a variable, but unlike C++ programming language, we cannot do that.
Well, so if you need a strict type in checking programming language, then we can use a language called
TypeScript.
All right.
So let's continue.
That is one point about is what is dynamically type language.
Next point about JavaScript is that it is object programming language.
So what does that mean?
It is a programming paradigm that uses object as a primary way of representing data, which uses what
is called prototype inheritance.
And this is also a topic on its own for the meantime.
Let's make it very simple here.
When we say prototype, it's a way to create new objects that inherit properties and methods from another
object.
Let me show you in a second.
So back to our Visual Studio code here.
I would say let's say objects.
Oriented programming, Opie.
Let's say we have this simple array with these values.
One, two, three, four, five.
So with the variable that we got, we have all the array methods.
For example, push, pop and shift, let's say pop.
Or a red dot push.
So all these methods, it is not me or you who made it.
This is possible because of what is called prototype inheritance.
That is why we say that JavaScript is object oriented programming language.
The next point is that it is a garbage collector and this means it is a process that frees up memory
by removing objects that are no longer used in the program.
And it's called Garbage Collection.
This is a cool feature about JavaScript, right?
And JavaScript runs in the browser, as you all know, until this point.
Apart from running JavaScript in the browser, we can also run JavaScript on the server with the help
of Node.js.
Now, lucky for us, we can run JavaScript in the browser at the same time on the server to create back
end application.
The next point about JavaScript is that it is non blocking, which means that it is the code that runs
concurrently in the background with the help of what is called event loop.
Event loop is also a big topic on its own.
As you move on, we will be more and explain what is event loop.
The next point is that JavaScript is non blocking, which means that it is a code that runs concurrently
in the background with the help of what is called event loop.
Event loop is also a big topic on its own.
As we move on, we will diving more and see what it means.
Well, with this particular point being raised, I think you will still have some doubt in your mind
that.
Well, the first point is that JavaScript is a single threaded language, but one is that for here we
can run more code concurrently.
Why is because of what is called the event loop?
For this one, if I try to explain to you where.
You may not be able to understand Parliament.
Try my best and see what you can do for the sick, for some people.
So let's see that.
Let's write a code that runs concurrently, meaning it doesn't wait for other code to finish running
for the first implementation day.
We see that it runs the code line by line.
So let's have a look for this particular example.
We are going to tweak, let's see Java a little bit to delay the execution of some code.
So let's see.
So let's comment here and say non blocking meaning it doesn't block other code from running.
So let's see.
So let's declare a variable, can't say hi, simple function error function as that.
And now let's say just console log, say hi for this one.
Now here comes the question how can we delay a certain function to be called at some point in time and
you are going to use a built in function or API call set timeout.
If we don't know it's a timeout.
That timeout is a function that's going to be called at some point in time.
So this is how we use it.
Set timeout.
And then as a function and this function takes in two arguments.
One is a function.
And next is the time you want this function to be called.
Let's say I want to call my callback function after 2 seconds, meaning 2000 milliseconds.
Is that so?
Inside my callback function here, I can do whatever I want.
I would say go to park.
Great.
So if I save this one, check the console.
You can see that after 2 seconds, something is going to be rendered, as you see, go to park.
So with this logic, we can delete this function call.
All right.
So we can call the function here inside this set timeout called say hello as a function as that.
Now I'm delaying this function to be called after 2 seconds.
Well, so down here or up here, let's console.log a function.
Say, go to bank.
Let's copy this function as my console.
Log down here and say Go to park.
If I save this file, what would be the order of execution?
If we are sticking to JavaScript is a single threaded.
It means that this function will call first immediately after I save the file and then after 2 seconds
this function will be called.
After that this will only be called.
That's a normal flow of JavaScript.
But with this using such timeout, the execution will be will be changed, meaning that let me increase
this one a little bit, let's say after 5 seconds.
So it means that this function down here will wait until this function calls.
But let's see when I save this.
Have a look.
You see that other response I got?
Go to bank and go to pot, and after 5 seconds I got high.
Meaning this function has the code, which is this one.
It means that this function did not block this particular function down here.
That is why as soon as I see the file, this one get called, go to bank this one, and then it skipped
this one and then got here and then display, I mean, go to park.
And lastly, after 5 seconds, I got this one as we see here.
And this is possible because of what is called the event loop.
And I said it would be more about why this one happened.
Great.
The next point is that JavaScript is a high level programming language, which means that any programming
language uses resources of a computer talking about computer memory CPU network before the application
can run.
But for low level programming languages like C and C++ and Java, developers need to manage these resources
manually by themselves.
But for high level programming languages like JavaScript, Python and Ruby programmers don't do this.
It is done for us automatically.
So that's why we say that JavaScript is what a high level programming language.
And when it says that JavaScript is a multi paradigm language, it means that we have different style
of approach.
How we can structure our code, we can write a code style called functional programming or object programming
or procedural programming.
So with one language we can adopt any of this approach to write our code.
That is what we call JavaScript.
A is a multi paradigm language, so that is it.
In this video we will talk about the V8 engine.