1
00:00:09,220 --> 00:00:15,610
Hey, everyone, in this lesson we are going to talk about no and undefined, so variables not always

2
00:00:15,610 --> 00:00:21,700
have values and no and undefined, they represent the lack of value.

3
00:00:22,030 --> 00:00:24,820
So I'm just going to create a new variable here.

4
00:00:25,300 --> 00:00:27,730
I'm going to name it no value.

5
00:00:28,170 --> 00:00:36,040
And instead of assigning a value to it, I could do something like equals an empty string because maybe

6
00:00:36,040 --> 00:00:38,680
I don't know the value yet.

7
00:00:38,710 --> 00:00:42,010
But instead of doing this, I don't have to assign anything.

8
00:00:42,250 --> 00:00:43,600
I can just create it.

9
00:00:45,170 --> 00:00:49,200
And now I have a variable called No Value.

10
00:00:49,560 --> 00:00:50,760
I can call it.

11
00:00:52,540 --> 00:00:57,640
But as you can see, the value assigned to this variable is undefined.

12
00:00:58,090 --> 00:01:06,340
If I try to do the type of operator to the no value variable, we can see that the type is undefined.

13
00:01:06,520 --> 00:01:08,770
So this is an actual data type.

14
00:01:08,950 --> 00:01:12,340
So other examples of undefined values.

15
00:01:12,640 --> 00:01:14,650
Let's create a variable for a.

16
00:01:15,760 --> 00:01:16,660
First name.

17
00:01:22,880 --> 00:01:31,060
Now, remember when we talked about strings, we said that a string is a sequence of characters.

18
00:01:31,360 --> 00:01:36,130
So we can't access each of these characters with an index.

19
00:01:36,430 --> 00:01:39,010
So the first character is index zero.

20
00:01:39,130 --> 00:01:40,730
This is going to return P.

21
00:01:41,170 --> 00:01:42,790
Then we have the second.

22
00:01:43,300 --> 00:01:46,210
Third, we can go all the way to the end.

23
00:01:46,300 --> 00:01:49,090
And if we try something that does not exist.

24
00:01:49,330 --> 00:01:52,150
So the last index of this string is four.

25
00:01:52,360 --> 00:01:53,570
If we try five.

26
00:01:53,980 --> 00:01:56,470
This is going to return undefined.

27
00:01:56,680 --> 00:02:01,870
So, as you can see, undefined really represents a lack of value.

28
00:02:02,590 --> 00:02:02,890
All right.

29
00:02:02,920 --> 00:02:04,210
So now let's talk about.

30
00:02:04,240 --> 00:02:07,720
No, no, it's not exactly a data type.

31
00:02:07,780 --> 00:02:10,570
And for many people, it should be avoided.

32
00:02:10,750 --> 00:02:14,110
I've just left a link of an article that you can read.

33
00:02:14,350 --> 00:02:17,200
So this guy is saying that you shouldn't use.

34
00:02:17,260 --> 00:02:17,800
No.

35
00:02:18,190 --> 00:02:21,370
And some people argue that you don't really need.

36
00:02:21,580 --> 00:02:22,060
No.

37
00:02:22,120 --> 00:02:22,720
So what is.

38
00:02:22,720 --> 00:02:23,230
No.

39
00:02:23,710 --> 00:02:25,630
Let's say I have a variable.

40
00:02:26,170 --> 00:02:28,750
So I'm going to create a variable called temperature.

41
00:02:30,380 --> 00:02:34,980
And I'm going to assign, let's say, 35 degrees Celsius.

42
00:02:35,610 --> 00:02:35,880
Right.

43
00:02:35,910 --> 00:02:37,890
So now I have the temperature.

44
00:02:38,400 --> 00:02:43,020
If I try to get this, we can see that thirty five has been assigned to it.

45
00:02:43,260 --> 00:02:48,710
So let's say I have a program that gets the temperature every minutes.

46
00:02:48,990 --> 00:02:50,820
So I go and try to get the temperature.

47
00:02:50,940 --> 00:02:56,160
Let's say we now try to get the temperature and we are unable to do it.

48
00:02:56,280 --> 00:02:58,350
We don't know if it's still 35.

49
00:02:58,410 --> 00:03:02,360
We don't know if it changed, but we don't have the actual temperature.

50
00:03:02,370 --> 00:03:03,600
We are trying to get it.

51
00:03:03,630 --> 00:03:09,270
But we did not receive and in fact, maybe there was a problem in the connection with the sensor.

52
00:03:09,690 --> 00:03:13,080
We just know that this time nothing came back.

53
00:03:13,530 --> 00:03:20,190
So instead of leaving the temperature that that it was before, we can set the temperature to know.

54
00:03:21,740 --> 00:03:28,100
So now if we call this variable, we can see that the value assigned to it is no.

55
00:03:28,340 --> 00:03:31,880
So this will tell the programmer that something went wrong.

56
00:03:32,180 --> 00:03:40,550
And then the programmer can write an exception and tell JavaScript what to do when we don't have a temperature

57
00:03:40,600 --> 00:03:41,050
back.

58
00:03:41,240 --> 00:03:47,890
Now, if I try to do the type off operator with the temperature variable, you can see that.

59
00:03:47,900 --> 00:03:50,570
No, it's not actually a data type.

60
00:03:50,900 --> 00:03:51,320
No.

61
00:03:51,320 --> 00:03:53,180
Is actually an object.

62
00:03:53,300 --> 00:03:56,210
So this is why this could be a bit confusing.

63
00:03:56,210 --> 00:03:58,760
But I personally like to use.

64
00:03:58,790 --> 00:04:02,420
No, because by using no, you can differentiate.

65
00:04:02,660 --> 00:04:08,600
One thing is a variable that never had any value assigned to it.

66
00:04:08,990 --> 00:04:13,880
And another thing is a variable that may be already had a value.

67
00:04:13,930 --> 00:04:16,000
But now it doesn't have anymore.

68
00:04:16,670 --> 00:04:19,220
So this is why I like doing it.

69
00:04:19,460 --> 00:04:22,940
So I'm going to create a new variable called Prasher.

70
00:04:23,750 --> 00:04:25,730
I'm not going to assign anything.

71
00:04:25,850 --> 00:04:29,000
So this means that I have never used this variable.

72
00:04:29,180 --> 00:04:32,330
So if I get its value, it's undefined.

73
00:04:32,990 --> 00:04:35,750
I've never used I've never assigned any value.

74
00:04:36,260 --> 00:04:39,380
Another thing is the temperature that already had a value.

75
00:04:39,560 --> 00:04:41,000
But now it's no.

76
00:04:41,090 --> 00:04:42,680
So it's really up to you.

77
00:04:42,710 --> 00:04:44,690
If you want to use no or not.

78
00:04:44,720 --> 00:04:47,360
Because in the end, we could just get the temperature.

79
00:04:47,600 --> 00:04:52,580
If we don't have the temperature, we can just set it to undefined as well.

80
00:04:52,640 --> 00:04:58,640
So this is why a lot of people think that no is really useless and that you should not use it.

81
00:04:59,240 --> 00:05:03,140
But while this is something that you might see on many programs.

82
00:05:03,320 --> 00:05:06,620
So I just wanted to show you that this exists.

83
00:05:06,890 --> 00:05:14,660
But in our examples from now one, we're just going to leave no aside and we are going to use undefined

84
00:05:14,930 --> 00:05:18,980
when we need to represent the lack of value.

85
00:05:19,430 --> 00:05:24,950
So I don't think there is nothing more about new and undefined that I need to say now.

86
00:05:24,950 --> 00:05:30,620
We just know that they exist and we will have opportunities to use them.

87
00:05:31,250 --> 00:05:35,300
So now it's time to do our first list of exercises.

88
00:05:35,510 --> 00:05:36,860
I'll see you in the next video.
