1
00:00:00,470 --> 00:00:07,160
Welcome back to Section to listen for common counsel errors, syntax and type references.

2
00:00:07,370 --> 00:00:13,840
So basically in JavaScript, the console is going to tell you if something went wrong most of the time,

3
00:00:13,880 --> 00:00:19,160
sometimes there are going to be problems that you won't notice because they won't reach the console

4
00:00:19,160 --> 00:00:25,610
or your code will run and it will compile in your code, thinks it's doing the right thing so there's

5
00:00:25,610 --> 00:00:26,390
no error.

6
00:00:26,390 --> 00:00:31,880
And so you're just going to have to go into your code and find out the problem or whatever, whatever

7
00:00:31,880 --> 00:00:34,760
thing is happening that's not showing you what you expect.

8
00:00:35,330 --> 00:00:40,670
So in those cases, you mostly just have to print out to the terminal, to the console what outputs

9
00:00:40,670 --> 00:00:45,410
you're expecting to see and then see if you need to change those at that time.

10
00:00:46,100 --> 00:00:51,560
But as far as built in errors, that will really help you understand if there's something wrong in your

11
00:00:51,560 --> 00:00:52,000
code.

12
00:00:52,400 --> 00:00:55,280
We have some that are built into the JavaScript console.

13
00:00:55,940 --> 00:00:57,440
One is a syntax error.

14
00:00:57,440 --> 00:01:02,870
So this is probably the most common and this is a load time error, which means that JavaScript has

15
00:01:02,870 --> 00:01:05,330
detected improper syntax in a statement.

16
00:01:06,170 --> 00:01:12,530
And the error message almost always tells you the exact line and character where the error occurs.

17
00:01:13,670 --> 00:01:19,550
And then there's the expected open parentheses or missing or expected close parentheses.

18
00:01:20,330 --> 00:01:28,220
And these are if you did not include a left parentheses or a right parentheses, then it will tell you

19
00:01:28,370 --> 00:01:35,960
that there's a mismatch and then you should be able to just go into your code at a specific line and

20
00:01:35,960 --> 00:01:38,520
fix that and then your code should run just fine.

21
00:01:39,320 --> 00:01:46,100
Likewise, if there's an expected curly brace open or close, curly brace, left or right, then it

22
00:01:46,100 --> 00:01:47,540
will notify you of that as well.

23
00:01:48,770 --> 00:01:55,670
If there is a semicolon that's required in a certain section of your code, which is basically any time

24
00:01:55,670 --> 00:02:01,220
you have the end of a line or the it's the end of a single action or expression of code in JavaScript,

25
00:02:01,610 --> 00:02:03,600
you should probably just put the semicolon.

26
00:02:03,620 --> 00:02:08,280
If it's not there, then sometimes it will get confused and not know what to do.

27
00:02:08,390 --> 00:02:10,520
Some languages don't require semicolons.

28
00:02:10,520 --> 00:02:11,960
Some require them all the time.

29
00:02:11,960 --> 00:02:17,270
With JavaScript, they're somewhat optional, but it's just a safe, better safe than sorry rule to

30
00:02:17,270 --> 00:02:19,820
just put semicolons at the end of each line of code.

31
00:02:21,670 --> 00:02:29,110
And then you will get an unexpected identifier or missing this error tells you that for some reason

32
00:02:29,110 --> 00:02:34,300
the previous statement didn't end properly for some reason or you've begun a new statement with an invalid

33
00:02:34,300 --> 00:02:34,780
value.

34
00:02:36,360 --> 00:02:41,610
So if JavaScript thinks you haven't finished a statement properly, maybe it's because the semicolon

35
00:02:41,610 --> 00:02:50,130
is missing, or maybe you forgot to include a the opening symbol for a multiline comment or something

36
00:02:50,130 --> 00:02:55,480
like that, some additional symbol is expected that is not being shown in your code.

37
00:02:56,280 --> 00:02:58,720
You might also see X is not defined.

38
00:02:58,770 --> 00:03:04,950
So this most often refers to if there's a specific variable that's not defined, it will be a variable

39
00:03:04,950 --> 00:03:10,650
named X that has not been declared or initialized or that you were trying to use in an expression.

40
00:03:11,160 --> 00:03:14,820
If that's the case, you just need to declare and initialize that variable.

41
00:03:15,570 --> 00:03:20,720
Another possible cause is that there is a string that isn't enclosed in quotation marks.

42
00:03:20,730 --> 00:03:26,220
So it's basically trying to read it as special keywords and it doesn't understand what those keywords

43
00:03:26,220 --> 00:03:26,520
mean.

44
00:03:26,880 --> 00:03:33,450
So you need to put a string, which is just a line of text in quotation marks, and then check to see

45
00:03:33,450 --> 00:03:38,760
if also if you've just misspelled your variable name, sometimes it can't find your variable or it says

46
00:03:38,760 --> 00:03:40,950
your variables not defined just because you misspelled it.

47
00:03:41,160 --> 00:03:45,330
You'll also see something that says X is not an object or X has no properties.

48
00:03:45,690 --> 00:03:52,950
That's if you try to use a variable as an object literal, but you don't give it properties or you're

49
00:03:52,950 --> 00:03:56,450
trying to use a string in the way that you'd use an object or something like that.

50
00:03:56,610 --> 00:04:03,000
Final one here is terminated, string constant or terminated string literal.

51
00:04:03,210 --> 00:04:08,520
Both of these messages mean that you started with a string, literal with a quotation mark, but forgot

52
00:04:08,520 --> 00:04:10,140
to close the quotation mark.

53
00:04:10,140 --> 00:04:14,750
So you started a line of text and you did not finish the line of text.

54
00:04:15,270 --> 00:04:21,420
You might also see another one that says a script on this page is causing your browser to run slowly.

55
00:04:22,180 --> 00:04:24,960
Do you want to abort the script or you'll see it?

56
00:04:25,130 --> 00:04:27,810
A lengthy JavaScript still running continue.

57
00:04:28,650 --> 00:04:32,580
And so these errors will tell you that your code is probably fallen into an infinite loop.

58
00:04:33,030 --> 00:04:37,620
And if you don't get any specific information about what's causing the problem, you'll need to scour

59
00:04:37,620 --> 00:04:40,050
your code to look for the possible cause.

60
00:04:40,480 --> 00:04:40,890
All right.

61
00:04:41,580 --> 00:04:45,780
I will include a link to the resource for this in the notes.

62
00:04:46,470 --> 00:04:51,810
That is basically the list of the common console errors that you're going to see and type references

63
00:04:52,170 --> 00:04:53,130
in JavaScript.

64
00:04:53,160 --> 00:04:55,650
So let's take a look at an example.

65
00:04:57,560 --> 00:05:02,950
OK, so if I wanted to show you some of these errors in the browser console, let's do that now.

66
00:05:03,160 --> 00:05:12,400
Got lesson four up in my e-mail and now it is doing a script tag in the head to call my index Dot James.

67
00:05:12,440 --> 00:05:20,000
So now my JS file is connected to my HTML file, so once I show it in the browser, I should be able

68
00:05:20,000 --> 00:05:21,830
to see the changes that are listed.

69
00:05:23,160 --> 00:05:28,800
OK, so if I wanted to print to the console, I can do that here, I can do console log.

70
00:05:30,030 --> 00:05:37,350
And I can just log string, all right, now, if I save that and then I run this again.

71
00:05:38,700 --> 00:05:43,230
Then there we go, we get this printout of hi to the council, because that's all they told it to do,

72
00:05:43,650 --> 00:05:52,140
go to my council and log or print out this variable in this variable has a value that says, hi, we're

73
00:05:52,140 --> 00:05:54,590
going to get a lot more into variable types and everything soon.

74
00:05:56,240 --> 00:06:01,340
All right, so what if we want to produce some errors here, let's see if we can produce some errors.

75
00:06:04,460 --> 00:06:08,560
So let's try that and do this again.

76
00:06:09,730 --> 00:06:13,830
And boom, uncaught syntax error, unexpected identifier.

77
00:06:13,900 --> 00:06:17,770
So it's saying what is wrong here, this doesn't make any sense.

78
00:06:17,800 --> 00:06:21,370
These are on the same line and it's understandable.

79
00:06:22,180 --> 00:06:27,870
So if I take it onto a new line, it will get rid of the error and it will understand it.

80
00:06:28,330 --> 00:06:34,130
But if we wanted to have it on a single line, we could as long as we separate the commands with semicolons.

81
00:06:34,450 --> 00:06:38,350
So that's why it's best to just have a semicolon at the end of your line.

82
00:06:39,220 --> 00:06:45,610
OK, if you wanted to see some of these others, what if we do a missing open parentheses?

83
00:06:46,090 --> 00:06:53,110
So if we do that and then refresh, we get another unexpected identifier.

84
00:06:55,490 --> 00:06:58,310
And if we do that same thing.

85
00:07:00,830 --> 00:07:06,650
Let's try to make another problem happen, so let's go undo.

86
00:07:10,960 --> 00:07:13,750
And let's not close this other.

87
00:07:15,530 --> 00:07:21,050
String here and see what problem is the syntax error, invalid or unexpected token?

88
00:07:21,950 --> 00:07:27,890
So this is saying that because we didn't close our quotes, OK, so that gets rid of the error there.

89
00:07:29,350 --> 00:07:33,280
And then we could see some other things like X is not defined.

90
00:07:33,310 --> 00:07:39,970
So if I take this and I put it into a comment, commenting something out basically makes it so that

91
00:07:39,970 --> 00:07:42,400
your code is not going to read it as a command.

92
00:07:42,400 --> 00:07:46,950
It's just going to acknowledge that it's simply a text note.

93
00:07:47,650 --> 00:07:49,640
So if I commented out, then it won't run.

94
00:07:50,680 --> 00:07:55,480
And so if I save and then refresh, we'll get uncaught.

95
00:07:55,480 --> 00:07:58,260
Reference, error star is not defined.

96
00:07:58,660 --> 00:08:01,020
So this means that our variable is not defined.

97
00:08:01,510 --> 00:08:08,590
We're going to need to define it, give it some initial value and state that it exists in order for

98
00:08:08,590 --> 00:08:11,830
it to be understood by the console.

99
00:08:12,400 --> 00:08:18,400
So let's bring that back out of the comment and you can either do your comments by two forward slashes

100
00:08:19,240 --> 00:08:21,280
or you can use just a shortcut.

101
00:08:21,280 --> 00:08:26,680
And most code editors, you can do a control forward slash or on Mac, a command forward slash.

102
00:08:28,160 --> 00:08:31,240
OK, so let's take that back out and see if that fixes the error.

103
00:08:32,250 --> 00:08:33,000
Yes, it does.

104
00:08:33,570 --> 00:08:33,900
OK.

105
00:08:34,790 --> 00:08:40,610
And then we could produce another one like, you know, an infinite loop, we could do an infinite loop

106
00:08:40,610 --> 00:08:41,300
with a for loop.

107
00:08:47,710 --> 00:08:49,660
So I'm building a little for loop right here.

108
00:08:55,190 --> 00:09:04,760
So normally a for loop would stop at a certain spot and then because it would reach this condition and

109
00:09:04,760 --> 00:09:05,280
then stop.

110
00:09:06,170 --> 00:09:14,870
But if we start at zero and we say as long as I'm less than zero, then continue until there, as long

111
00:09:14,870 --> 00:09:16,130
as I'm greater than zero.

112
00:09:18,610 --> 00:09:23,860
Let's start at one, OK, so I created a for loop and we're starting it one.

113
00:09:24,750 --> 00:09:30,420
And now, if I say I is greater than zero, as long as I is greater than zero, then continue to the

114
00:09:30,420 --> 00:09:33,720
next line and increase, I buy one.

115
00:09:34,390 --> 00:09:36,830
OK, well, it's just going to keep doing that.

116
00:09:36,840 --> 00:09:40,170
If I is greater than zero, it will increase by one, etc..

117
00:09:40,500 --> 00:09:41,850
So let's save it and run it.

118
00:09:44,460 --> 00:09:45,510
And let's do.

119
00:09:47,820 --> 00:09:49,230
Console that log.

120
00:10:04,290 --> 00:10:08,040
OK, now that we've set up our infinite loop, let's run it and see what happens.

121
00:10:12,000 --> 00:10:19,110
OK, as you can see, we created a problem, it won't stop waiting and thinking, it's really, really

122
00:10:19,110 --> 00:10:20,430
trying hard to get this right.

123
00:10:22,240 --> 00:10:23,220
Let's take this out.

124
00:10:24,420 --> 00:10:25,110
And save it.

125
00:10:27,380 --> 00:10:29,180
And let's force refresh this page.

126
00:10:37,500 --> 00:10:42,690
All right, so we got rid of the infinite loop and we eliminated the problem of it just spinning forever

127
00:10:42,690 --> 00:10:43,050
and ever.

128
00:10:44,680 --> 00:10:47,380
So that's just a few examples of these.

129
00:10:48,440 --> 00:10:50,420
Common JavaScript error messages.

130
00:10:52,400 --> 00:10:53,300
Let's get back.

131
00:10:54,260 --> 00:11:00,190
To our reference, so, yeah, that was a lesson for common errors, for syntax and reference type errors,

132
00:11:00,560 --> 00:11:05,690
you will see these a lot, you'll see these all over the place when you put in some code and expect

133
00:11:05,690 --> 00:11:07,890
to get something, but you don't get what you expected.

134
00:11:08,510 --> 00:11:12,890
Thankfully, the council log is going to do you a whole lot of good by telling you what those errors

135
00:11:12,890 --> 00:11:13,080
are.

136
00:11:13,550 --> 00:11:19,430
OK, so for our next lesson, we're going to switch gears a little bit and learn about terminal.

137
00:11:20,300 --> 00:11:27,200
The terminal is something that a command line terminal essentially is something that we have on Windows,

138
00:11:27,200 --> 00:11:36,130
on Mac, on Linux, and it will allow us to manipulate the computer from just a command line.

139
00:11:36,260 --> 00:11:41,390
So we'll just actively, Anderson, codes that will allow us to navigate the computer.

140
00:11:41,960 --> 00:11:45,050
OK, let's stop there and we'll see you in the next video.

141
00:11:45,080 --> 00:11:45,470
Thank you.
