1
00:00:02,420 --> 00:00:07,970
Now we wrote some code already, a feature which you can also use in Javascript and many other programming

2
00:00:07,970 --> 00:00:16,340
languages are comments. You can add comments to your code to make it more understandable to fellow developers

3
00:00:16,550 --> 00:00:17,600
or to yourself

4
00:00:17,600 --> 00:00:23,540
if you were coming back to your code after a couple of months of break or something like that. Now a comment

5
00:00:23,540 --> 00:00:26,050
in Javascript can be added in two ways,

6
00:00:26,150 --> 00:00:30,830
you can add it here, like you add regular code by adding two forward slashes,

7
00:00:30,890 --> 00:00:32,530
this is a comment

8
00:00:32,540 --> 00:00:38,710
now. This means that this is there for people to read but it has no effect on your code.

9
00:00:38,750 --> 00:00:42,200
If you reload, you don't see an error or anything like that,

10
00:00:42,230 --> 00:00:48,650
it's not executed as code, instead this is just there to comment your code, to make it more understandable.

11
00:00:49,400 --> 00:00:54,030
If you have a longer a comment to write which should be split across multiple lines,

12
00:00:54,050 --> 00:01:00,350
you can of course add another line of comments here with two other forward slashes but you can also add a

13
00:01:00,350 --> 00:01:08,320
block comment by adding a forward slash and then a star and now you see everything is green down there

14
00:01:08,350 --> 00:01:13,060
because now everything after that is treated as a comment,

15
00:01:13,150 --> 00:01:15,930
so this is also a comment

16
00:01:16,330 --> 00:01:18,160
and this is

17
00:01:18,160 --> 00:01:24,130
and now you have to close the comment with a star and another forward slash, so the opposite combination

18
00:01:24,130 --> 00:01:25,820
we had here to open it.

19
00:01:25,840 --> 00:01:31,660
So now this allows you to write a longer comment across multiple lines without starting every line with

20
00:01:31,660 --> 00:01:33,780
two forward slashes.

21
00:01:33,850 --> 00:01:36,970
Now how will you use comments in your code?

22
00:01:36,970 --> 00:01:39,910
You shouldn't comment the obvious,

23
00:01:39,910 --> 00:01:44,590
so if you comment this is a function that

24
00:01:47,080 --> 00:01:51,980
extracts the user input from the input field,

25
00:01:52,030 --> 00:01:57,760
that's not the best comment because for one you don't want to write long text, you don't want to write

26
00:01:57,880 --> 00:01:59,220
essays here,

27
00:01:59,230 --> 00:02:05,980
instead you want to write short to-the-point comments that add some extra context or understanding that

28
00:02:06,100 --> 00:02:08,970
isn't obvious from looking at the code.

29
00:02:08,980 --> 00:02:15,790
So if I look at this code, it's pretty obvious at what it does, we could just add something like gets

30
00:02:15,790 --> 00:02:17,790
input from input field.

31
00:02:17,830 --> 00:02:18,970
Why is that useful?

32
00:02:18,970 --> 00:02:24,970
Because it adds this extra context that this is coming from an input field because it might not be obvious,

33
00:02:24,970 --> 00:02:31,150
by looking at the code, that user input refers to input field, so that could be something we could add

34
00:02:31,360 --> 00:02:36,580
to make understanding that code a bit easier and simply save the developer who's looking at the code

35
00:02:36,700 --> 00:02:41,570
to time to kind of find out what user input is referring to.

36
00:02:41,710 --> 00:02:50,450
Here we could add something like generates and writes calculation log, again

37
00:02:50,460 --> 00:02:55,860
this might not really be necessary because that's quite easy to see if you look at this but if you have

38
00:02:55,860 --> 00:03:00,540
a first quick look at this, it could look daunting and then this makes it clear that this is in the end

39
00:03:00,550 --> 00:03:08,510
just a helper function that outputs some information and generates that information as well. You can

40
00:03:08,570 --> 00:03:10,400
also add a comment inline,

41
00:03:10,400 --> 00:03:17,210
so after some code, like here, we could say from vendor file to make it clear that this function is not

42
00:03:17,210 --> 00:03:20,620
defined somewhere in this file but lives in the vendor file,

43
00:03:20,630 --> 00:03:22,470
otherwise this might not be obvious

44
00:03:22,490 --> 00:03:28,250
and again if someone wants to follow our code or understand it, this could help with understanding it.

45
00:03:28,250 --> 00:03:32,580
So adding such a short inline comment also sometimes can be useful.

46
00:03:32,810 --> 00:03:38,870
In general, you want to comment your code, especially if you share it with others but you don't want to

47
00:03:38,960 --> 00:03:39,860
overdo it,

48
00:03:40,010 --> 00:03:42,410
don't add redundant information,

49
00:03:42,410 --> 00:03:48,200
don't write too long comments because then people will not read them at all and they actually get less

50
00:03:48,290 --> 00:03:54,020
out of them than if there were no comments at all and you don't want to comment the obvious, instead

51
00:03:54,200 --> 00:04:01,790
provide some extra context, extra information that can help understand your code faster or briefly share

52
00:04:01,820 --> 00:04:04,510
your thoughts regarding the code you wrote here.

53
00:04:04,520 --> 00:04:06,680
That's something you could add with comments.
