1
00:00:00,860 --> 00:00:07,560
All right guys so we briefly talked about symbols back in the data types lecture back in the I think

2
00:00:07,560 --> 00:00:12,750
it was the second section very very briefly we didn't even really talk about what they were we just

3
00:00:12,750 --> 00:00:16,250
established that they were in fact a primitive data type.

4
00:00:16,530 --> 00:00:16,980
OK.

5
00:00:16,980 --> 00:00:19,650
And they're part of the ESX standard.

6
00:00:19,650 --> 00:00:23,830
So let's go ahead and experiment a little bit with symbols.

7
00:00:23,850 --> 00:00:28,970
So I have my index each team and we're just linking to an app J.S. file which is completely empty.

8
00:00:28,980 --> 00:00:36,540
I have it open over here in my browser and the unique thing about symbols is that every single one is

9
00:00:36,540 --> 00:00:37,850
completely unique.

10
00:00:37,860 --> 00:00:43,470
And this makes them very valuable in terms of things like object property identifiers.

11
00:00:43,470 --> 00:00:44,770
And this is the main sim.

12
00:00:44,790 --> 00:00:48,230
The main purpose of symbols is their uniqueness.

13
00:00:48,420 --> 00:00:52,580
So let's go ahead and create a symbol.

14
00:00:52,580 --> 00:00:52,940
All right.

15
00:00:52,950 --> 00:01:00,480
So we can create a variable say Constable call it on and we're going to set it equal to symbol just

16
00:01:00,480 --> 00:01:01,360
like that.

17
00:01:01,360 --> 00:01:01,710
All right.

18
00:01:01,740 --> 00:01:03,980
Now it's not new symbol.

19
00:01:04,320 --> 00:01:09,950
OK we'll get an error because there's no constructor it's an actual primitive value.

20
00:01:10,170 --> 00:01:14,240
OK we can also add an identifier inside of our symbol if we want.

21
00:01:14,240 --> 00:01:20,920
So right here we want to say like CYM to assume to set this variable the same too.

22
00:01:21,330 --> 00:01:30,530
And if we go ahead and console da log say Sim one it's just going to simply give us symbol we logs to

23
00:01:30,570 --> 00:01:31,710
It'll give us symbol.

24
00:01:31,710 --> 00:01:33,980
Along with that identifier.

25
00:01:34,020 --> 00:01:34,310
All right.

26
00:01:34,320 --> 00:01:41,150
Now if we want to look at the type we can say type is the type of operator and that gives a symbol.

27
00:01:41,250 --> 00:01:44,180
OK so this is this.

28
00:01:44,190 --> 00:01:47,420
This tells us that this is a primitive data value.

29
00:01:48,430 --> 00:01:52,060
So it doesn't return the type object or anything like that.

30
00:01:52,060 --> 00:01:58,210
It's a pure primitive value which is symbol all right or pure pin primitive type.

31
00:01:58,270 --> 00:02:00,820
Now no two symbols can be the same.

32
00:02:00,820 --> 00:02:16,700
So even if we were to do even if we were to do it say console got log in let's say symbol equal to symbol.

33
00:02:17,090 --> 00:02:17,530
OK.

34
00:02:17,560 --> 00:02:20,270
So if we do that we say we're going to get false.

35
00:02:20,450 --> 00:02:20,770
OK.

36
00:02:20,770 --> 00:02:24,490
Because they can never equal they can never be the same.

37
00:02:24,510 --> 00:02:30,870
Even if we put the same identifier in here let's say 1 to 3 and say.

38
00:02:30,910 --> 00:02:33,420
Still false.

39
00:02:33,460 --> 00:02:42,400
All right if we were to try to use a symbol inside of a string like if we were to put to use tactics

40
00:02:42,400 --> 00:02:48,060
here and we'll just say hello and we'll put in the sim one variable.

41
00:02:48,130 --> 00:02:53,350
If we go ahead and run that we're going to get cannot convert symbol value to a string but if we wanted

42
00:02:53,350 --> 00:02:56,740
to we could wrap it in the string function

43
00:03:00,080 --> 00:03:02,560
subseries string should be in here.

44
00:03:05,630 --> 00:03:06,650
So it could go like that.

45
00:03:06,680 --> 00:03:08,780
We'll get the helo symbol.

46
00:03:08,780 --> 00:03:11,870
You could also do if you don't want to wrap it in the string.

47
00:03:11,870 --> 00:03:17,180
I mean there's not too many reasons you do this but just to show you can you can also do two string

48
00:03:17,180 --> 00:03:20,140
like that and that'll work.

49
00:03:20,160 --> 00:03:30,980
All right Snell's to get into them one of the main reasons for symbols and that is unique object keys.

50
00:03:30,980 --> 00:03:31,310
All right.

51
00:03:31,320 --> 00:03:44,290
So if we were to create let's say key one and set this equal to symbol Hamil's say Konst key to and

52
00:03:44,610 --> 00:03:51,160
set that to symbol even give this one an ID of sim too.

53
00:03:51,180 --> 00:03:51,540
All right.

54
00:03:51,550 --> 00:03:55,370
I'm just going to comment those.

55
00:03:55,440 --> 00:03:55,740
All right.

56
00:03:55,740 --> 00:04:03,330
And then what we could do is create an object so will say my object set that to an object and then we

57
00:04:03,330 --> 00:04:05,430
can add these keys.

58
00:04:05,430 --> 00:04:05,750
All right.

59
00:04:05,760 --> 00:04:12,030
Now whenever you want to use a variable as a key you don't want to go like this.

60
00:04:12,030 --> 00:04:21,870
Key one equals oh say prop 1 because what it's doing is it's just looking at this as a normal property.

61
00:04:21,870 --> 00:04:28,120
All right if you want to use an actual variable then you want to use the brackets syntax like this.

62
00:04:28,120 --> 00:04:32,890
All right so that first one was not using this variable I was just using.

63
00:04:32,940 --> 00:04:39,450
Key one is a property in this case we're using the actual symbol as a property.

64
00:04:39,570 --> 00:04:47,600
All right and if we wanted to create another one we could do the two and said that as Prop 2.

65
00:04:47,610 --> 00:04:49,590
All right and if we console log

66
00:04:52,560 --> 00:05:06,320
I will do my OB stot are not dog key one and save and we have prop one if we console log by August 2

67
00:05:06,350 --> 00:05:08,720
we should get Proc. to.

68
00:05:09,420 --> 00:05:09,750
All right.

69
00:05:09,750 --> 00:05:16,910
So there are some things that that work a little different with symbols for one.

70
00:05:17,040 --> 00:05:26,550
If we were to loop through my obs using for n then it wouldn't actually show up in the iteration because

71
00:05:26,550 --> 00:05:29,520
they're not enumerable in four in iteration.

72
00:05:29,520 --> 00:05:33,740
So let me show you what I mean some of these symbols are not

73
00:05:36,470 --> 00:05:41,040
numerable in 4.

74
00:05:41,360 --> 00:05:44,030
So if we were to say for

75
00:05:46,780 --> 00:05:57,530
let's say for let I in my age and then what I wanted to do before I do anything here I'm going to go

76
00:05:57,530 --> 00:06:03,590
ahead and just add to the my object but not using a symbol I'm just going to say my object Daut will

77
00:06:03,590 --> 00:06:05,020
call it key 3.

78
00:06:05,150 --> 00:06:11,910
But remember this isn't a symbol it's just a simple property and we'll set that to prop 3.

79
00:06:12,190 --> 00:06:16,280
And let's say my AABs Daut key four equals

80
00:06:19,480 --> 00:06:20,330
four.

81
00:06:20,600 --> 00:06:29,300
So down here we'll go ahead and console log and let's get the key and the value so I will give us the

82
00:06:29,300 --> 00:06:29,770
key.

83
00:06:29,770 --> 00:06:37,430
I'm going to put some back ticks in here and will say I which will give us the key and then to get the

84
00:06:37,430 --> 00:06:41,790
value we'll say my age.

85
00:06:42,410 --> 00:06:45,520
I think that will save.

86
00:06:45,770 --> 00:06:49,310
Actually we need to get rid of these console's and save.

87
00:06:49,490 --> 00:06:55,300
And now you see we just get T3 and key for OK we're looping through this.

88
00:06:55,320 --> 00:07:01,330
The my obs which has all of these in it the two symbols and the two regular properties.

89
00:07:01,460 --> 00:07:07,610
Yet only the two regular properties are showing up here because symbols again are not enumerable for

90
00:07:07,910 --> 00:07:09,490
in for in loops.

91
00:07:09,530 --> 00:07:10,140
OK.

92
00:07:10,370 --> 00:07:18,000
So just remember that another thing is that symbols are ignored when using Jason dot string of phi.

93
00:07:18,020 --> 00:07:18,350
All right.

94
00:07:18,350 --> 00:07:24,830
Now Jason does string of what it does is it takes javascript object literal and turns it into adjacent

95
00:07:24,830 --> 00:07:25,750
string.

96
00:07:25,760 --> 00:07:27,260
So let me give you an example.

97
00:07:27,260 --> 00:07:36,200
First of all I'm going to put a comment here that says symbols are ignored by Jason Dodd stratified

98
00:07:36,200 --> 00:07:48,110
so say Konsole dog log and let's say Jason Daut string of phi and go ahead and put a regular object

99
00:07:48,110 --> 00:07:53,130
in here we'll just say the set to the string of Propp.

100
00:07:53,150 --> 00:08:01,420
So if we save that you're going to comment that you'll see that it logs it as a Giese in a string.

101
00:08:01,610 --> 00:08:01,940
All right.

102
00:08:01,940 --> 00:08:08,350
Now if we were to do the same thing here using a symbol as a key.

103
00:08:08,720 --> 00:08:17,570
So let's get rid of that and we'll just go ahead and put in brackets and say symbol say symbol and we'll

104
00:08:17,570 --> 00:08:24,960
give it an idea of some one and we'll go ahead and save and you'll see that it's just an empty object.

105
00:08:24,980 --> 00:08:27,610
OK so it doesn't actually.

106
00:08:27,620 --> 00:08:31,090
It doesn't actually parse as as this one did.

107
00:08:31,470 --> 00:08:37,430
OK so just some things that are just different when you're using symbols.

108
00:08:37,430 --> 00:08:37,700
All right.

109
00:08:37,700 --> 00:08:41,600
So I think that's going to do it for now for symbols in the next video.

110
00:08:41,600 --> 00:08:45,680
What I want to do is talk about error handling We haven't really got into that yet.

111
00:08:45,680 --> 00:08:50,420
I want to talk about try catch blocks and how to throw errors things like that.

112
00:08:50,420 --> 00:08:52,560
All right so I will see you in the next lecture.

