1
00:00:02,320 --> 00:00:05,440
Now that is it for functions;

2
00:00:05,440 --> 00:00:08,420
we learned a couple of new features related

3
00:00:08,420 --> 00:00:11,280
to functions that can sometimes be useful,

4
00:00:11,280 --> 00:00:14,323
and we had a brief look behind the scenes of functions.

5
00:00:15,210 --> 00:00:17,580
Now I wanna come back to one line of code

6
00:00:17,580 --> 00:00:20,420
that we have here that we can also improve

7
00:00:20,420 --> 00:00:24,040
with some advanced JavaScript code.

8
00:00:24,040 --> 00:00:26,860
And that's this line here,

9
00:00:26,860 --> 00:00:31,860
or specifically it's this part here in this line

10
00:00:32,460 --> 00:00:35,360
where we are constructing that string

11
00:00:35,360 --> 00:00:38,490
by combining some hard coded strings,

12
00:00:38,490 --> 00:00:41,130
like the "blank" or the "exclamation mark,"

13
00:00:41,130 --> 00:00:44,830
with some dynamic pieces, the values

14
00:00:44,830 --> 00:00:46,863
we get here in these parameters.

15
00:00:48,130 --> 00:00:50,390
We can build a string like this,

16
00:00:50,390 --> 00:00:54,293
but JavaScript also has an alternative for us.

17
00:00:55,430 --> 00:00:58,530
Instead of building that string like that,

18
00:00:58,530 --> 00:01:00,500
and hence I'll comment it out,

19
00:01:00,500 --> 00:01:05,250
we can also use a feature called Template Literals

20
00:01:05,250 --> 00:01:07,533
that's built into JavaScript.

21
00:01:08,450 --> 00:01:10,100
For this, we can build a string

22
00:01:10,100 --> 00:01:13,750
by using backticks instead of single quotes,

23
00:01:13,750 --> 00:01:15,230
and that's important.

24
00:01:15,230 --> 00:01:17,910
These backtick characters here are

25
00:01:17,910 --> 00:01:20,420
special characters on your keyboard;

26
00:01:20,420 --> 00:01:24,440
it's not the regular single quote.

27
00:01:24,440 --> 00:01:27,750
It's a special character which you'll have on your keyboard,

28
00:01:27,750 --> 00:01:30,660
and you can use backticks to create a string,

29
00:01:30,660 --> 00:01:33,373
like "Hi there" as we did before.

30
00:01:34,390 --> 00:01:36,440
But we typically don't use backticks

31
00:01:36,440 --> 00:01:39,290
to just create a regular string like that;

32
00:01:39,290 --> 00:01:43,260
instead, these backticks give us some powerful features:

33
00:01:43,260 --> 00:01:47,070
For one, they allow us to write multiline strings.

34
00:01:47,070 --> 00:01:50,390
We can add line breaks inside of the string,

35
00:01:50,390 --> 00:01:54,570
and that's not possible if we use single quotes;

36
00:01:54,570 --> 00:01:56,330
if we try to do that,

37
00:01:56,330 --> 00:01:59,543
we instead get some errors as you can see here.

38
00:02:00,380 --> 00:02:02,723
So that's one advantage of using backticks.

39
00:02:06,340 --> 00:02:08,979
But the even more useful advantage is

40
00:02:08,979 --> 00:02:12,810
that you can easily plug in dynamic values into

41
00:02:12,810 --> 00:02:15,790
that string without having to concatenate

42
00:02:15,790 --> 00:02:19,713
and combine a lot of pieces with the plus operator.

43
00:02:20,620 --> 00:02:24,410
Instead, if we wanna rebuild the string from up there,

44
00:02:24,410 --> 00:02:27,850
we can just add a special syntax in here

45
00:02:27,850 --> 00:02:29,703
to plug in our greetingPrefix.

46
00:02:31,320 --> 00:02:34,360
We use the "$" sign and then "opening

47
00:02:34,360 --> 00:02:36,870
and closing curly brace,"

48
00:02:36,870 --> 00:02:40,370
and you see that this now gets highlighted by my IDE

49
00:02:40,370 --> 00:02:44,420
because it's detected as a special piece of syntax.

50
00:02:44,420 --> 00:02:46,730
And between those curly braces,

51
00:02:46,730 --> 00:02:50,000
you can now put your variable, or constant,

52
00:02:50,000 --> 00:02:54,250
or parameter value that you wanna output here,

53
00:02:54,250 --> 00:02:56,083
for example, greetingPrefix.

54
00:02:57,070 --> 00:02:58,930
Then you can add a white space

55
00:02:58,930 --> 00:03:01,820
and maybe add another placeholder

56
00:03:01,820 --> 00:03:04,410
where you plug in the username,

57
00:03:04,410 --> 00:03:07,143
and then we have the "exclamation mark" thereafter.

58
00:03:08,300 --> 00:03:12,300
This will construct the same kind of string we saw before.

59
00:03:12,300 --> 00:03:14,610
Hence, if I execute this file,

60
00:03:14,610 --> 00:03:18,320
we, again, get "Hi Max" and "Hello user,"

61
00:03:18,320 --> 00:03:23,320
but it does so in a shorter, more concise way

62
00:03:23,450 --> 00:03:27,120
with help of these placeholders here

63
00:03:27,120 --> 00:03:31,483
where we plug in dynamic values into a string.

64
00:03:32,620 --> 00:03:35,650
And that is another feature that can be useful,

65
00:03:35,650 --> 00:03:39,470
especially if you are constructing very long strings

66
00:03:39,470 --> 00:03:42,360
with a lot of dynamic values.

67
00:03:42,360 --> 00:03:46,070
Then you can avoid having all these extra plus operators

68
00:03:46,070 --> 00:03:48,660
and concatenating strings with each other,

69
00:03:48,660 --> 00:03:50,730
and you can just write one string

70
00:03:50,730 --> 00:03:53,923
with some dynamic values inside of that string.

