🍿Template strings
Template strings are a way to create strings that include dynamic content. They are created using backticks (`) instead of single or double quotes.
Here is an example of a template string:
const name = 'John';
console.log(`Hello, ${name}!`); // Outputs "Hello, John!"
Template strings can also span multiple lines:
const message = `Welcome to
my adventure game!`;
console.log(message); // Outputs "Welcome to\nmy adventure game!"
Template strings can also include expressions, which are evaluated and the result is included in the string. This is called interpolation.
For example:
const a = 10;
const b = 20;
console.log(`The sum of ${a} and ${b} is ${a + b}.`); // Outputs "The sum of 10 and 20 is 30."
Let's look at another example in the context of a Strategy Game
Last updated