
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is the importance of ES6's template strings in JavaScript?
ES6's template strings is a new way to combine strings. We already have methods such as join(), concat() etc to combine strings but the template strings method is the most sophisticated because it’s more readable, no backslash to escape quotes and no more messy plus operators.
Using concat() and join()
Example
In the following example join() and concat() methods are used to combine strings. If we observe carefully the code looks very messy.
<html> <body> <script> const platform = 'Tutorix'; const joinMethod = ['The', 'best', 'e-learning', 'platform', 'is', platform].join(' '); document.write(joinMethod); document.write("</br>"); const concatMethod = " ".concat('The ', 'best ', 'e-learning ', 'platform ', 'is ', platform); document.write(concatMethod); </script> </body> </html>
Output
The best e-learning platform is Tutorix The best e-learning platform is Tutorix
Using ES6's Template Strings
Example
In the following example, the template strings method is used to combine strings. If we compare this method with other methods, the code in this method is very concise and readable.
<html> <body> <script> const platform = 'Tutorix'; const templateString = `The best e-learning platform is ${platform}`; document.write(templateString); </script> </body> </html>
Output
The best e-learning platform is Tutorix
- Related Articles
- Template strings in JavaScript.
- ES6/ECMA6 template literals not working in JavaScript?
- Formatted Strings Using Template Strings in JavaScript
- Nesting template strings in JavaScript
- What is the importance of Symbol.isConcatSpreadable in JavaScript?
- What is the importance of Math.trunc() method in JavaScript?
- What is the importance of _isEqual() method in JavaScript?
- What is the importance of _without() method in JavaScript?
- What is the importance of _.initial() function in JavaScript?
- What is the importance of _.union() method in JavaScript?
- What is the importance of Navigator Object in JavaScript?
- What is the importance of str.padStart() method in JavaScript?
- What is importance of startsWith() method in JavaScript?
- What is the relationship between JavaScript, CoffeeScript, TypeScript, ES5, and ES6?
- What is the importance of extracurricular activities in a student's life?

Advertisements