Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript String Literals

JS String Template Literals

Template Literals use back-ticks (``) rather than the quotes ("") to define a string.

					 
        
          let text1 = "Hello World!";
          let text2 = 'Hello World!';
          let text3 = `Hello World!`;
        
      
Quotes Inside Strings

With template literals, you can use both single and double quotes inside a string.

					 
        
          let text = `He's often called "Johnny"`;
        
      
Multiline Strings

Template literals allows multiline strings

					 
        
          let text =
              `Lynxsia
               IT
               Solutions`;
        
      
Interpolation

Template literals provide an easy way to interpolate variables and expressions into strings. The method is called string interpolation.

Syntax

Variable Substitutions

Template literals allow variables in strings.

					 
        
          let firstName = "John";
          let lastName = "Doe";
          let text = `Welcome ${firstName}, ${lastName}!`;
        
      
Expression Substitutions

Template literals allow expressions in strings.

					 
        
          let price = 10;
          let VAT = 0.25;
          let total = `Total: ${(price * (1 + VAT)).toFixed(2)}`;
        
      
HTML Element

Template literals allow us to use HTML in the string.

					 
        
          let header = "Lynxsia IT Solutions";
          let html = `<h2>${header}</h2>`;
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved