Nowadays, JavaScript is one of the most powerful and widely used programming language, and day by
day it becomes more and more popular in the world.
Therefore, there is a huge demand on JavaScript developers, and that's the main reason why I have
decided to create this section throughout the course.
You have met almost everything that you need to know regarding JavaScript today, and if you have understood
and learned all of this stuff, well, then I guarantee that you won't have any trouble to start the
job, at least as JavaScript developer.
But regardless of that, I'm going to go through the commonly asked questions on JavaScript interviews
and also show you relevant answers.
I would like to recommend you to post the video after each question, think about it and try to remind
the answer and check if you are correct or not.
The first question that is commonly asked after releasing its sixth version is the following.
What is the difference among the Latin cast variable declarations?
All right, let's recall it once again, the first thing that I want to note is that the declaration
has been using since JavaScript was created.
As for the Latin declarations, they are added in essence version.
At first I'm going to compare VA to both Latin constant declarations.
The main distinction between them is scoping variables with var declaration or function scoped and Latin
Carlstadt blocks called.
OK, let's write an example, create function A.
That inside code block create variable B.
Which equals the 10.
And run it in council, right, Costa Lockpick.
Without that, we have an error saying that B is not defined.
That's because Variable B is created inside scope of Function A. And we do not have access on this variable
outside function at the same will happen if we use that.
And also concerned.
But in case of if statements, then the result will be different.
Let's create if and as a condition right here.
True.
Then create variable inside call, the prices were equal to 10.
And then run it in council.
Reload and he said that we have done so, it means that one variable is created with var declaration,
it's accessible from outside the block.
It means that VA is not the block skulked, as you know, in block.
I mean, everything that is between curly braces, that's for the letton cost.
If we change VA into that, then we will get an error, which tells us that A is not defined and the
exact same happens if we change that into cost.
So still, we have an ever.
All right, the next difference between Valette and cost variable declarations is the following if we
create a variable using VAR and then run it in council, but right before declaration.
Then we will get undefined, and that's because of hoisting, but when we use let or const.
Instead of undefined, we get an error is not defined.
All right, now let's see differences between left and cost declarations, I'm sure that you remember
them.
Why don't we use that declaration?
We can reassign to it the value.
So that's right.
A course of ten, then a equals to 220.
And run it in council.
So you see that value of air is changed from 10 to 20.
But in case of consent, it's not possible if we change all that into cost.
Then we will get an error assignment to Kossuth Variable, so if we don't want to change the value of
a variable, then we have to use constant declaration.
Another distinction between cost and that is that if you declare that variable and not assigned a value
to it.
Then it will be undefined, but in case of constant variable.
We cannot do it if we declare the variable using cost, then we definitely need to assign value to it.
All right, let's move on to the next question, which is the following what is the difference between
undefined and now undefined and primitive data types?
They both mean that the variable doesn't have the value, but the difference is that undefined is automatically
assigned to a variable when it's declared you don't have to do it manually.
JavaScript engine does it automatically, but now is an assignment value.
When you want the variable to have no value, then you have to assign to it.
Now, actually, you can assign undefined MANUELITA variable, but it's not recommended.
Besides that, if you check type of undefined and now you will get different results.
Right, consultative type of.
A defined.
And do the same for.
No.
So in case of undefiled, we have type of define, but as for now, we have an object.
Actually undefined and now is kind of confusing part of JavaScript and interviewers like to ask questions
about them.
All right.
The next then one of the most commonly asked question is the difference between composing operators,
which are double equals and triple equals, double equals comprise an operator who compares all of the
values.
Let's say we have variables, let A equals the 10 and that B equals to ten as well.
Let's run in Castle A double equals B.
So you say that we have to because those values are definitely equal, if we change double equal to
triple equals, then we will get still through because the values and also types are equal.
Both variables are numbers.
If we change one of the values into spring and also change triple equals into double equals, then we
will get to because as we said, double equals comparison.
The values are not data types.
And here in both cases, we have values as the opposite happens if we use triple equals.
We will get false because it appears that all of the values, but also the data types and in this case,
we have no string.
All right, let's go ahead and see what is the next question?
What is the difference between function statements and function expressions?
Let's create both of them.
In case of function statement, we have to write following Function A.
And then Calabrese ride right, consider log high Asfour function expression's, we have to create variable
and assign to it anonymous function the right variable be equal to function.
And then running castle.
Hello, let's invoke both of them.
Then reload and we have high and hello.
Both functions work, but if we call them before, they are declarations.
Then for function statement, we will get the same results, but for function expression, we will get
an error, which tells us that B is not a function.
So this is the main and kind of insignificant difference between function statement and function expression.
All right, let's move on to the next question, which is about the difference between regular functions
and arole functions.
Actually, erro functions are released, a new version of JavaScript in Essex.
And the first and obvious difference between regular and eral functions is in syntax at birth.
Let's write constants a equals to function and place your parameters X and Y and then return the sum
of those parameters, then invoke the function right.
Consider log A with the arguments as five and ten.
So this is a regular function expression.
And now let's write erro function.
Right, constant P equals inserting parentheses parameters X and Y that are all function.
And again, it's the sum of Paramjit X and Y.
Let's invoke function B, right, cancel that log.
Be with the arguments 20 and 30.
Reload and we have 50 so many differences in syntax is that in case of error functions, we don't use
keyword function.
If we have only one statement in code block like it's here that we don't need to use Calabrese.
And even returned Keywood.
Also, if we have only one parameter, then we don't need to use parentheses, but in case if we do
not have any parameters, then we need to place empty parentheses here.
The next and more important difference between regular and error functions is about this special, this
variable.
Let's use another example.
I'm going to select hatting element, which we have on page here.
Actually, this is known example for you, but because of that, it's very important.
I'm going to show you again, let's select hatting elements and attach the event.
Listener writes, document that query selector.
Then right here, H1 an element and attached to it, event listener with click event that place your
anonymous function.
And inside that anonymous function creates function expression, right, concerned a.
He calls the function.
And let's run in council, this variable also invoke function A.
Let's reload and click on Harding, you see that in case of regular function, this variable points
to global window object.
But if we change a regular function into a role function.
Then this what will change dereference and it will point to the elements on which event listener is
attached.
It happens because this variable of erro function points to the same object as its surroundings.
Culp's, this variable does, but on a global level, both refer to global.
We object.
OK, let's go ahead and see what is the next question.
Next question is about hoisting.
From many developers and also in many resources online, it will make the following definition about
hosting, hosting means that JavaScript engine physically moves variable declarations.
But honestly, it's not quite correct, actually, JavaScript engine doesn't move the code physically,
so let me explain once again what hoisting means.
Before the code runs, JavaScript engine on the creation phase automatically assigns to variables undefined.
So let's write the example create variable AI, which equals to hello.
That run it in council, but write it before the verbal declaration.
Reload.
And we have undefined so as we know, JavaScript engine reads the code line by line, from top to down.
At first it found Castle Dot Log A and because of that, at this point, the value to variable is assigned
as undefined.
We got undefined.
So again, remember, that engine doesn't move code physically.
It just assigns automatically undefined two variables on the creation phase.
All right.
Let's discuss another possible question that you may have gotten interview.
So what isn't immediately invoked function expression and what it is used for, immediately invoked
function expression or simply if it is function, which is invoked immediately after its declaration
in order to create if we need to place parentheses and write in its anonymous function.
And then after or before closing brace, we need to place another parenthesis, let's right inside it,
cancel the clock.
Hello?
Reload and we have hello.
Actually, if it is a great tool in JavaScript, they're used for to create blocks for data privacy
and also we use them in order to avoid naming conflicts.
Besides that, if it's not great when we write the code using module pattern, which you have already
seen in our quiz application project.
All right.
The next question that I want to show you is actually one of the most commonly asked one.
And it refers to closure's.
There is really higher chance to get this question on your JavaScript interview, so let's recall what
closures are.
I'm going to create a very simple example, right?
Function A inside.
It creates constant X, which equals to five.
Then return function.
And in that function.
Create another variable Y, which equals the 10.
And then running castle to some of these variables, X plus Y, let's invoke those functions right consent.
Equals to a.
And that call be
revoked and we have 15.
So when the function is executed, then a return function still has access on variable X and happens
because of the closure.
So in general, closures save the variables even when the function finishes execution.
All right.
So I have represented some of the probably ask questions on JavaScript interviews and I have demonstrated
briefly answers on some of these topics are explained in detail throughout the course.
So if you still do not feel confident in those topics, then I recommend to watch videos again.
Actually, I cannot guarantee 100 percent that those questions will be asked on your interview, but
it's common experience and there is a higher chance to get the questions like these.
Honestly, I would be glad and excited if I could help you.