Learn
Variables
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 ${}
.
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.
Instructions
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