1// To use interpolation in strings, put the name of the relevant
2// variable between brackets {} and put a dollar sign $ in front
3// of the string. This will tell C# to use interpolation.
4double a = 3;
5double b = 4;
6Console.WriteLine($"Area of {a} and {b} is {0.5 * a * b}");
1/*In order to embed expressions within normal strings,
2you would use the following syntax:*/
3let a = 5;
4let b = 10;
5console.log('Fifteen is ' + (a + b) + ' and\nnot ' + (2 * a + b) + '.');
6// "Fifteen is 15 and
7// not 20."
8
9/*Now, with template literals, you are able to make use of the syntactic sugar,
10making substitutions like this more readable:*/
11let a = 5;
12let b = 10;
13console.log(`Fifteen is ${a + b} and
14not ${2 * a + b}.`);
15// "Fifteen is 15 and
16// not 20."
1var message1 = interpolate("turkey");
2console.log(message1); // "My favorite food is turkey!"
3
4var message2 = interpolate("tofurkey");
5console.log(message2); // "My favorite food is tofurkey!"
6
1const number = 42;
2const message = `The number is ${number}`;
3
4message; // => 'The number is 42'