Code highlights logo



String Interpolation

Another way to concatenate strings with variables is by using string interpolation. This method allows us to embed variables directly within a template string by using placeholders ${}.

1let age = 25;
2let message = `I am ${age} years old.`;
3console.log(message); // Output: I am 25 years old.

In the above example, we have a variable age which is embedded within the template string using ${age}. The value of age is dynamically inserted into the string when it is evaluated, resulting in the output I am 25 years old..

String interpolation provides a cleaner and more readable way to concatenate strings with variables, especially when dealing with complex expressions or multiple variables.



Replace the string concatenation with string interpolation using backticks (``) and template literals (${}) in the console.log() statement.
Use template literals to interpolate the name, age, and profession variables inside the string.

Sign up to start coding

Already have an account?

Sign In

Course content