WEBVTT

00:00.870 --> 00:06.330
Nowadays, JavaScript is one of the most powerful and widely used programming language, and day by

00:06.330 --> 00:08.680
day it becomes more and more popular in the world.

00:09.390 --> 00:14.490
Therefore, there is a huge demand on JavaScript developers, and that's the main reason why I have

00:14.490 --> 00:17.940
decided to create this section throughout the course.

00:17.940 --> 00:23.640
You have met almost everything that you need to know regarding JavaScript today, and if you have understood

00:23.640 --> 00:28.500
and learned all of this stuff, well, then I guarantee that you won't have any trouble to start the

00:28.500 --> 00:31.220
job, at least as JavaScript developer.

00:31.920 --> 00:37.170
But regardless of that, I'm going to go through the commonly asked questions on JavaScript interviews

00:37.170 --> 00:39.720
and also show you relevant answers.

00:40.900 --> 00:46.660
I would like to recommend you to post the video after each question, think about it and try to remind

00:46.660 --> 00:49.640
the answer and check if you are correct or not.

00:50.800 --> 00:56.020
The first question that is commonly asked after releasing its sixth version is the following.

00:56.800 --> 01:01.270
What is the difference among the Latin cast variable declarations?

01:02.910 --> 01:08.580
All right, let's recall it once again, the first thing that I want to note is that the declaration

01:08.580 --> 01:11.190
has been using since JavaScript was created.

01:11.730 --> 01:15.540
As for the Latin declarations, they are added in essence version.

01:16.230 --> 01:20.730
At first I'm going to compare VA to both Latin constant declarations.

01:21.300 --> 01:28.590
The main distinction between them is scoping variables with var declaration or function scoped and Latin

01:28.590 --> 01:30.090
Carlstadt blocks called.

01:31.070 --> 01:34.700
OK, let's write an example, create function A.

01:37.450 --> 01:41.200
That inside code block create variable B.

01:43.000 --> 01:44.020
Which equals the 10.

01:46.250 --> 01:49.460
And run it in council, right, Costa Lockpick.

01:52.840 --> 01:57.140
Without that, we have an error saying that B is not defined.

01:57.880 --> 02:04.330
That's because Variable B is created inside scope of Function A. And we do not have access on this variable

02:04.330 --> 02:09.310
outside function at the same will happen if we use that.

02:13.500 --> 02:15.480
And also concerned.

02:18.240 --> 02:22.140
But in case of if statements, then the result will be different.

02:22.770 --> 02:27.000
Let's create if and as a condition right here.

02:27.000 --> 02:27.420
True.

02:29.240 --> 02:34.070
Then create variable inside call, the prices were equal to 10.

02:35.320 --> 02:36.910
And then run it in council.

02:40.330 --> 02:47.410
Reload and he said that we have done so, it means that one variable is created with var declaration,

02:47.770 --> 02:49.980
it's accessible from outside the block.

02:50.560 --> 02:54.790
It means that VA is not the block skulked, as you know, in block.

02:54.790 --> 02:59.400
I mean, everything that is between curly braces, that's for the letton cost.

02:59.410 --> 03:08.440
If we change VA into that, then we will get an error, which tells us that A is not defined and the

03:08.440 --> 03:11.920
exact same happens if we change that into cost.

03:14.840 --> 03:16.400
So still, we have an ever.

03:18.180 --> 03:24.330
All right, the next difference between Valette and cost variable declarations is the following if we

03:24.330 --> 03:33.840
create a variable using VAR and then run it in council, but right before declaration.

03:36.380 --> 03:43.250
Then we will get undefined, and that's because of hoisting, but when we use let or const.

03:46.220 --> 03:51.290
Instead of undefined, we get an error is not defined.

03:55.070 --> 04:00.890
All right, now let's see differences between left and cost declarations, I'm sure that you remember

04:00.890 --> 04:01.170
them.

04:01.690 --> 04:03.200
Why don't we use that declaration?

04:03.200 --> 04:05.410
We can reassign to it the value.

04:05.810 --> 04:06.690
So that's right.

04:07.040 --> 04:11.090
A course of ten, then a equals to 220.

04:12.140 --> 04:13.940
And run it in council.

04:16.670 --> 04:20.180
So you see that value of air is changed from 10 to 20.

04:20.810 --> 04:25.370
But in case of consent, it's not possible if we change all that into cost.

04:26.410 --> 04:32.740
Then we will get an error assignment to Kossuth Variable, so if we don't want to change the value of

04:32.740 --> 04:35.560
a variable, then we have to use constant declaration.

04:36.910 --> 04:42.610
Another distinction between cost and that is that if you declare that variable and not assigned a value

04:42.610 --> 04:43.030
to it.

04:45.930 --> 04:50.190
Then it will be undefined, but in case of constant variable.

04:52.980 --> 04:59.430
We cannot do it if we declare the variable using cost, then we definitely need to assign value to it.

05:01.100 --> 05:06.830
All right, let's move on to the next question, which is the following what is the difference between

05:06.830 --> 05:11.420
undefined and now undefined and primitive data types?

05:11.420 --> 05:18.020
They both mean that the variable doesn't have the value, but the difference is that undefined is automatically

05:18.020 --> 05:22.820
assigned to a variable when it's declared you don't have to do it manually.

05:22.820 --> 05:27.980
JavaScript engine does it automatically, but now is an assignment value.

05:28.670 --> 05:32.950
When you want the variable to have no value, then you have to assign to it.

05:32.960 --> 05:38.790
Now, actually, you can assign undefined MANUELITA variable, but it's not recommended.

05:39.830 --> 05:45.290
Besides that, if you check type of undefined and now you will get different results.

05:46.940 --> 05:49.130
Right, consultative type of.

05:50.940 --> 05:51.960
A defined.

05:54.500 --> 05:55.910
And do the same for.

05:57.570 --> 05:57.990
No.

05:59.160 --> 06:05.250
So in case of undefiled, we have type of define, but as for now, we have an object.

06:06.920 --> 06:13.490
Actually undefined and now is kind of confusing part of JavaScript and interviewers like to ask questions

06:13.490 --> 06:14.040
about them.

06:14.930 --> 06:15.440
All right.

06:15.470 --> 06:21.230
The next then one of the most commonly asked question is the difference between composing operators,

06:21.230 --> 06:26.690
which are double equals and triple equals, double equals comprise an operator who compares all of the

06:26.690 --> 06:27.310
values.

06:27.950 --> 06:35.320
Let's say we have variables, let A equals the 10 and that B equals to ten as well.

06:36.050 --> 06:39.500
Let's run in Castle A double equals B.

06:42.610 --> 06:48.800
So you say that we have to because those values are definitely equal, if we change double equal to

06:48.820 --> 06:54.510
triple equals, then we will get still through because the values and also types are equal.

06:55.000 --> 06:56.440
Both variables are numbers.

06:57.600 --> 07:04.620
If we change one of the values into spring and also change triple equals into double equals, then we

07:04.620 --> 07:08.190
will get to because as we said, double equals comparison.

07:08.270 --> 07:09.960
The values are not data types.

07:10.710 --> 07:16.470
And here in both cases, we have values as the opposite happens if we use triple equals.

07:18.080 --> 07:24.050
We will get false because it appears that all of the values, but also the data types and in this case,

07:24.050 --> 07:25.910
we have no string.

07:26.900 --> 07:30.190
All right, let's go ahead and see what is the next question?

07:31.280 --> 07:35.160
What is the difference between function statements and function expressions?

07:36.620 --> 07:38.000
Let's create both of them.

07:39.350 --> 07:43.310
In case of function statement, we have to write following Function A.

07:45.560 --> 07:53.420
And then Calabrese ride right, consider log high Asfour function expression's, we have to create variable

07:53.810 --> 08:00.230
and assign to it anonymous function the right variable be equal to function.

08:03.010 --> 08:04.270
And then running castle.

08:06.490 --> 08:10.630
Hello, let's invoke both of them.

08:13.990 --> 08:17.490
Then reload and we have high and hello.

08:18.070 --> 08:22.900
Both functions work, but if we call them before, they are declarations.

08:24.160 --> 08:30.820
Then for function statement, we will get the same results, but for function expression, we will get

08:30.820 --> 08:34.150
an error, which tells us that B is not a function.

08:35.270 --> 08:41.720
So this is the main and kind of insignificant difference between function statement and function expression.

08:42.560 --> 08:47.720
All right, let's move on to the next question, which is about the difference between regular functions

08:47.720 --> 08:48.920
and arole functions.

08:49.520 --> 08:53.570
Actually, erro functions are released, a new version of JavaScript in Essex.

08:54.020 --> 08:59.950
And the first and obvious difference between regular and eral functions is in syntax at birth.

08:59.960 --> 09:10.700
Let's write constants a equals to function and place your parameters X and Y and then return the sum

09:10.940 --> 09:15.250
of those parameters, then invoke the function right.

09:15.260 --> 09:21.390
Consider log A with the arguments as five and ten.

09:22.250 --> 09:24.860
So this is a regular function expression.

09:25.560 --> 09:27.860
And now let's write erro function.

09:28.400 --> 09:36.140
Right, constant P equals inserting parentheses parameters X and Y that are all function.

09:37.270 --> 09:41.560
And again, it's the sum of Paramjit X and Y.

09:43.990 --> 09:47.380
Let's invoke function B, right, cancel that log.

09:48.550 --> 09:51.790
Be with the arguments 20 and 30.

09:54.330 --> 10:02.210
Reload and we have 50 so many differences in syntax is that in case of error functions, we don't use

10:02.210 --> 10:03.170
keyword function.

10:03.470 --> 10:09.490
If we have only one statement in code block like it's here that we don't need to use Calabrese.

10:12.390 --> 10:14.100
And even returned Keywood.

10:18.040 --> 10:24.840
Also, if we have only one parameter, then we don't need to use parentheses, but in case if we do

10:24.840 --> 10:28.470
not have any parameters, then we need to place empty parentheses here.

10:28.890 --> 10:34.500
The next and more important difference between regular and error functions is about this special, this

10:34.500 --> 10:35.070
variable.

10:35.760 --> 10:37.320
Let's use another example.

10:37.330 --> 10:40.840
I'm going to select hatting element, which we have on page here.

10:41.570 --> 10:45.310
Actually, this is known example for you, but because of that, it's very important.

10:45.330 --> 10:50.730
I'm going to show you again, let's select hatting elements and attach the event.

10:50.730 --> 10:55.770
Listener writes, document that query selector.

10:58.490 --> 11:07.850
Then right here, H1 an element and attached to it, event listener with click event that place your

11:07.850 --> 11:08.780
anonymous function.

11:10.980 --> 11:16.410
And inside that anonymous function creates function expression, right, concerned a.

11:17.570 --> 11:18.650
He calls the function.

11:21.790 --> 11:30.490
And let's run in council, this variable also invoke function A.

11:33.010 --> 11:39.670
Let's reload and click on Harding, you see that in case of regular function, this variable points

11:39.670 --> 11:41.020
to global window object.

11:42.430 --> 11:45.520
But if we change a regular function into a role function.

11:47.250 --> 11:54.120
Then this what will change dereference and it will point to the elements on which event listener is

11:54.120 --> 11:54.630
attached.

11:55.830 --> 12:04.010
It happens because this variable of erro function points to the same object as its surroundings.

12:04.020 --> 12:09.360
Culp's, this variable does, but on a global level, both refer to global.

12:09.360 --> 12:10.150
We object.

12:10.710 --> 12:13.890
OK, let's go ahead and see what is the next question.

12:14.340 --> 12:16.200
Next question is about hoisting.

12:17.710 --> 12:23.260
From many developers and also in many resources online, it will make the following definition about

12:23.260 --> 12:28.900
hosting, hosting means that JavaScript engine physically moves variable declarations.

12:29.860 --> 12:36.420
But honestly, it's not quite correct, actually, JavaScript engine doesn't move the code physically,

12:37.240 --> 12:39.700
so let me explain once again what hoisting means.

12:40.730 --> 12:48.610
Before the code runs, JavaScript engine on the creation phase automatically assigns to variables undefined.

12:49.130 --> 12:54.890
So let's write the example create variable AI, which equals to hello.

12:57.110 --> 13:03.260
That run it in council, but write it before the verbal declaration.

13:05.920 --> 13:06.460
Reload.

13:07.450 --> 13:13.260
And we have undefined so as we know, JavaScript engine reads the code line by line, from top to down.

13:13.870 --> 13:20.230
At first it found Castle Dot Log A and because of that, at this point, the value to variable is assigned

13:20.230 --> 13:21.040
as undefined.

13:21.490 --> 13:22.580
We got undefined.

13:23.560 --> 13:27.670
So again, remember, that engine doesn't move code physically.

13:28.240 --> 13:32.290
It just assigns automatically undefined two variables on the creation phase.

13:33.280 --> 13:33.670
All right.

13:34.120 --> 13:37.830
Let's discuss another possible question that you may have gotten interview.

13:38.440 --> 13:44.890
So what isn't immediately invoked function expression and what it is used for, immediately invoked

13:44.890 --> 13:51.430
function expression or simply if it is function, which is invoked immediately after its declaration

13:52.510 --> 13:57.430
in order to create if we need to place parentheses and write in its anonymous function.

14:00.520 --> 14:08.800
And then after or before closing brace, we need to place another parenthesis, let's right inside it,

14:09.130 --> 14:10.030
cancel the clock.

14:10.540 --> 14:11.080
Hello?

14:14.560 --> 14:16.220
Reload and we have hello.

14:17.260 --> 14:24.610
Actually, if it is a great tool in JavaScript, they're used for to create blocks for data privacy

14:24.970 --> 14:27.890
and also we use them in order to avoid naming conflicts.

14:28.810 --> 14:33.850
Besides that, if it's not great when we write the code using module pattern, which you have already

14:33.850 --> 14:35.980
seen in our quiz application project.

14:37.570 --> 14:38.040
All right.

14:38.590 --> 14:43.210
The next question that I want to show you is actually one of the most commonly asked one.

14:43.210 --> 14:45.400
And it refers to closure's.

14:46.280 --> 14:51.710
There is really higher chance to get this question on your JavaScript interview, so let's recall what

14:51.710 --> 14:52.760
closures are.

14:52.790 --> 14:55.910
I'm going to create a very simple example, right?

14:55.910 --> 14:59.370
Function A inside.

14:59.370 --> 15:03.200
It creates constant X, which equals to five.

15:04.270 --> 15:05.710
Then return function.

15:07.370 --> 15:08.900
And in that function.

15:10.230 --> 15:14.040
Create another variable Y, which equals the 10.

15:16.470 --> 15:26.640
And then running castle to some of these variables, X plus Y, let's invoke those functions right consent.

15:28.560 --> 15:30.090
Equals to a.

15:31.320 --> 15:33.150
And that call be

15:35.820 --> 15:37.780
revoked and we have 15.

15:38.970 --> 15:46.830
So when the function is executed, then a return function still has access on variable X and happens

15:46.830 --> 15:47.880
because of the closure.

15:48.870 --> 15:54.570
So in general, closures save the variables even when the function finishes execution.

15:55.440 --> 15:55.940
All right.

15:56.370 --> 16:02.640
So I have represented some of the probably ask questions on JavaScript interviews and I have demonstrated

16:02.640 --> 16:07.910
briefly answers on some of these topics are explained in detail throughout the course.

16:08.400 --> 16:14.210
So if you still do not feel confident in those topics, then I recommend to watch videos again.

16:15.440 --> 16:21.260
Actually, I cannot guarantee 100 percent that those questions will be asked on your interview, but

16:21.260 --> 16:25.730
it's common experience and there is a higher chance to get the questions like these.

16:27.020 --> 16:30.650
Honestly, I would be glad and excited if I could help you.
