Skip to content

Instantly share code, notes, and snippets.

@tararoutray
Created August 31, 2021 15:22
Show Gist options
  • Save tararoutray/884db23570f3277f685275f7521159f9 to your computer and use it in GitHub Desktop.
Save tararoutray/884db23570f3277f685275f7521159f9 to your computer and use it in GitHub Desktop.
// Let's declare a constant with name "user".
const user = 'John';
// Another constant with name "age".
const age = '24';
// Let's see how we can use the above information to print in the console
// using the template literals
const message = `Welcome ${user}! Your age is ${age}`;
// The following will print:
// Welcome John! Your age is 24
console.log(message);
// A benifit of using template literal is, you can write multi line HTML code
// without getting any error from the compiler. See the below snippet:
const htmlMessage = `
<h1>Welcome ${user}!</h1>
<h5>Your age is ${age}</h5>
`;
// The template literals is better than using regular string concatenations like 'hello ' + 'world'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment