Template Literals

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€85.54
List Price:  €119.76
You save:  €34.22
£74.07
List Price:  £103.71
You save:  £29.63
CA$136.98
List Price:  CA$191.77
You save:  CA$54.79
A$151.99
List Price:  A$212.79
You save:  A$60.80
S$128.05
List Price:  S$179.28
You save:  S$51.22
HK$784.89
List Price:  HK$1,098.88
You save:  HK$313.99
CHF 79.61
List Price:  CHF 111.46
You save:  CHF 31.84
NOK kr1,012.69
List Price:  NOK kr1,417.81
You save:  NOK kr405.12
DKK kr637.93
List Price:  DKK kr893.13
You save:  DKK kr255.20
NZ$166.37
List Price:  NZ$232.92
You save:  NZ$66.55
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳12,155.75
List Price:  ৳17,018.53
You save:  ৳4,862.78
₹8,582.32
List Price:  ₹12,015.60
You save:  ₹3,433.27
RM425.20
List Price:  RM595.30
You save:  RM170.10
₦152,836.71
List Price:  ₦213,977.51
You save:  ₦61,140.80
₨28,434.65
List Price:  ₨39,809.65
You save:  ₨11,375
฿3,244.17
List Price:  ฿4,541.96
You save:  ฿1,297.79
₺4,016.46
List Price:  ₺5,623.20
You save:  ₺1,606.74
B$555.95
List Price:  B$778.35
You save:  B$222.40
R1,792.06
List Price:  R2,508.95
You save:  R716.89
Лв167.31
List Price:  Лв234.24
You save:  Лв66.93
₩137,902.20
List Price:  ₩193,068.60
You save:  ₩55,166.40
₪333.07
List Price:  ₪466.32
You save:  ₪133.24
₱5,648.28
List Price:  ₱7,907.82
You save:  ₱2,259.53
¥14,737.62
List Price:  ¥20,633.26
You save:  ¥5,895.64
MX$1,863.83
List Price:  MX$2,609.44
You save:  MX$745.60
QR364.02
List Price:  QR509.64
You save:  QR145.62
P1,334.67
List Price:  P1,868.59
You save:  P533.92
KSh12,948.70
List Price:  KSh18,128.70
You save:  KSh5,180
E£4,948.92
List Price:  E£6,928.69
You save:  E£1,979.76
ብር13,688.63
List Price:  ብር19,164.63
You save:  ብር5,476
Kz91,690.83
List Price:  Kz128,370.83
You save:  Kz36,680
CLP$95,713.42
List Price:  CLP$134,002.62
You save:  CLP$38,289.20
CN¥716.78
List Price:  CN¥1,003.52
You save:  CN¥286.74
RD$6,029.39
List Price:  RD$8,441.39
You save:  RD$2,412
DA12,974.97
List Price:  DA18,165.48
You save:  DA5,190.50
FJ$224.34
List Price:  FJ$314.09
You save:  FJ$89.74
Q767.92
List Price:  Q1,075.11
You save:  Q307.19
GY$20,914.76
List Price:  GY$29,281.51
You save:  GY$8,366.74
ISK kr12,179.78
List Price:  ISK kr17,052.18
You save:  ISK kr4,872.40
DH900.15
List Price:  DH1,260.25
You save:  DH360.10
L1,687.60
List Price:  L2,362.71
You save:  L675.10
ден5,265.96
List Price:  ден7,372.56
You save:  ден2,106.59
MOP$808.30
List Price:  MOP$1,131.65
You save:  MOP$323.35
N$1,772.82
List Price:  N$2,482.02
You save:  N$709.20
C$3,674.63
List Price:  C$5,144.63
You save:  C$1,470
रु13,711.85
List Price:  रु19,197.15
You save:  रु5,485.29
S/354.61
List Price:  S/496.47
You save:  S/141.86
K412.45
List Price:  K577.45
You save:  K165
SAR375.01
List Price:  SAR525.03
You save:  SAR150.02
ZK2,343.77
List Price:  ZK3,281.37
You save:  ZK937.60
L434.63
List Price:  L608.50
You save:  L173.87
Kč2,109.72
List Price:  Kč2,953.70
You save:  Kč843.97
Ft34,185.58
List Price:  Ft47,861.18
You save:  Ft13,675.60
SEK kr955.94
List Price:  SEK kr1,338.36
You save:  SEK kr382.41
ARS$126,192.13
List Price:  ARS$176,674.04
You save:  ARS$50,481.90
Bs692.26
List Price:  Bs969.19
You save:  Bs276.93
COP$401,297.58
List Price:  COP$561,832.67
You save:  COP$160,535.08
₡50,416.70
List Price:  ₡70,585.39
You save:  ₡20,168.69
L2,634.73
List Price:  L3,688.73
You save:  L1,054
₲774,763.12
List Price:  ₲1,084,699.36
You save:  ₲309,936.24
$U4,064.43
List Price:  $U5,690.36
You save:  $U1,625.93
zł364.86
List Price:  zł510.83
You save:  zł145.96
Already have an account? Log In

Transcript

Hello, in this JavaScript video I am going to cover template literals. So these are a new cool way in f6 for creating strings, so let's create a regular string var fully str equals, remember he single quotation mark or double quotation marks last Regulus claim, and I'm gonna say hello, we'll need to log in as the console. Save that. Reload the page, we are hello world. Man if the string is quite long, and we want to pull your multiple lines ourselves, if we do that, we'll get an error. This is not valid syntax.

That's the same if we were to replace this with a single quotation mark, it doesn't work either. So template literal use the back kick so recently to a single quotation mark, but It's a slightly slanted trigger the backtick on a Mac, it's old. And it's that key towards the bottom left that by default saves, you know, forward slash on a regular keyboard just above the start command key. So that and that will be the backtick. If you not too sure what to use on Windows or on any other platform, just have a quick do water, feel free to pop me a message and I'll help you out once you put the backtick. And if we run this, honestly, we actually first not saved.

All right, we still get the same, but look what happens. It still work but this is on multiple lines. And this acts as if this is a multi line string so that you know one feature, they might think that the only thing actually no, there's a few other cool things. Number one, and maybe I will one, what I'm actually going to do is first create a variable Could be a lead variable, it could just be a VAR variable doesn't really matter. We're gonna call this age. And I'm gonna set this to prefix that is my current age.

And I am going to put, you know, the backtick. And in here, usually if we want to, to basically concatenate on or put in a very low variable into a string would have to do you know, something like plus no age, obviously, I know it's not created yet, but that's sort of what you would have to do, especially if it's in the middle you need to close the quotation marks, put the variable in open quotation marks and it just this is too much hassle if you have a lot of variables inside you know, a string. Instead, what we can do is my name, I mean, my age is, instead of closing quotation marks or anything like that, you just put Donna curly braces, the variable name And then we can continue watching this. And I am. And I'll call it more to just to distinguish a little difference between the two variables, console dot log, try to run it.

As you can see, my age is 26. And I am Batman. So that allowed me to insert all the variables directly inside of me and you know, do calculations inside here as well. So this is a very, very powerful thing. So it's our calculation isn't 26 times seven, which is 182. So that's the great thing about template literals.

And it's one of the new awesome features in JavaScript. If you have any questions, feel free to shoot me a message and evil. Thanks for watching, and I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.