1
00:00:00,210 --> 00:00:05,730
And you might get a question like this, what will do logged in the first example and in the second

2
00:00:05,730 --> 00:00:06,270
example.

3
00:00:09,450 --> 00:00:15,810
To answer correctly, you must understand the difference between null and undefined inside JavaScript,

4
00:00:16,110 --> 00:00:18,210
as you can see here, we have two examples.

5
00:00:18,480 --> 00:00:24,990
In first example, we didn't assign anything to our variable, which means this variable is not defined

6
00:00:24,990 --> 00:00:25,260
yet.

7
00:00:25,560 --> 00:00:28,140
This is why we went here with console.log this variable.

8
00:00:28,320 --> 00:00:34,620
It will be equal undefined and here after this were console.log and the type of this variable and the

9
00:00:34,620 --> 00:00:37,320
name of the type will also be undefined.

10
00:00:37,470 --> 00:00:43,950
And here we have our second example where inside our variable tool were signed null value and here were

11
00:00:43,950 --> 00:00:45,300
console.log Envato.

12
00:00:45,420 --> 00:00:48,430
And as you can understand, here we have our value now.

13
00:00:48,660 --> 00:00:50,460
This is what we will see on the screen.

14
00:00:50,730 --> 00:00:55,950
But type of variable too will be an object because there is no such type as now.

15
00:00:56,100 --> 00:00:58,800
This is why the type of variable is an object.

16
00:00:58,920 --> 00:01:02,640
Let's check this out and alert the page and we get in here and define it.

17
00:01:02,940 --> 00:01:07,420
This is our variable one here saw the value of it is undefined.

18
00:01:07,520 --> 00:01:10,470
The type of undefined is undefined as screen.

19
00:01:10,680 --> 00:01:14,250
Now, after this work, console.log invert to here where I get now.

20
00:01:14,460 --> 00:01:18,180
This is our value and type of variable to is an object.

21
00:01:18,360 --> 00:01:23,360
So you really must distinguish in JavaScript between now and undefined undefined.

22
00:01:23,370 --> 00:01:29,250
It means that the variable is declared, but the value is not assigned yet inside this variable.

23
00:01:29,460 --> 00:01:35,400
This is exactly what we have here on Line three and null in JavaScript is an assignment value, which

24
00:01:35,400 --> 00:01:41,880
means it's a value that we can assign inside the variable in our case here, where sign in null inside

25
00:01:41,880 --> 00:01:42,780
variable tomb.

26
00:01:43,050 --> 00:01:46,830
And even if you answered correctly here into the human might ask you.

27
00:01:46,950 --> 00:01:50,190
But what is really the difference between now and undefined?

28
00:01:50,370 --> 00:01:53,700
Well, we need to use null and when we need to use and define it.

29
00:01:54,000 --> 00:01:59,790
And actually, it is a tricky one because normally in normal languages, we have only a single property,

30
00:01:59,970 --> 00:02:03,450
which means that the variable does not exist, for example, Neal.

31
00:02:03,660 --> 00:02:06,030
But in JavaScript, we have two different things.

32
00:02:06,030 --> 00:02:08,220
We have undefined and we have now.

33
00:02:08,460 --> 00:02:14,160
And actually, it really depends on your coattail and your team because you can use both of them inside

34
00:02:14,160 --> 00:02:14,730
project.

35
00:02:14,910 --> 00:02:21,180
But for example, I prefer to always use on Nahles and try to have as little undefined INTs as possible.

36
00:02:21,450 --> 00:02:27,150
But obviously, if you are trying to find a value inside the ray, you will get that undefined and not

37
00:02:27,150 --> 00:02:29,520
null because we didn't find anything.

38
00:02:29,910 --> 00:02:35,430
So the answer here that it is fine to use both of them and that is not really something better in one

39
00:02:35,430 --> 00:02:36,090
or another.
