Javascript - String Literal

String literal is sequence of characters enclosed in single quotes ( ' ), double quotes ( " ) and backticks ( ` ).

We can say String literal represent text in the code.

  • Single quoted strings: 'Hello Ajay'
  • Double quoted strings: "Hello Ajay"
  • Template Literals: `Hello Ajay`

Template Literals: enclosed in backticks ( ` ), Allow for multi-line strings and string interpolation.

let name = "Ajay"

Example:- let info = `Hello ${name}`

Template Literals:

let name = 'Ajay'
let message = 'Hello ${name} welcome here!'
console.log(message) // Hello Ajay welcome here!         

  • String Interpolation: Easily embed expressions within strings. let info = `Hello ${name}`
  • Multi-line Strings: Create multi-line strings without concatenation.
  • Embedded Expressions: Embed any JavaScript expression. let fullName = `Name: ${name} , Phone: ${phone}`
  • Improved Readability: Enhance code readability, especially for complex strings.

Useful link to get more details about Template Literal: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

𝗙𝗲𝗲𝗹 𝗳𝗿𝗲𝗲 𝘁𝗼 𝗰𝗼𝗺𝗺𝗲𝗻𝘁 𝘄𝗶𝘁𝗵 𝗺𝗼𝗿𝗲 𝘂𝘀𝗲𝗳𝘂𝗹 𝗱𝗲𝘁𝗮𝗶𝗹𝘀

#𝘫𝘴 #𝘫𝘢𝘷𝘢𝘴𝘤𝘳𝘪𝘱𝘵 #𝘳𝘦𝘢𝘤𝘵𝘫𝘴 #𝘪𝘯𝘵𝘦𝘳𝘷𝘪𝘦𝘸 #𝘣𝘦𝘨𝘪𝘯𝘯𝘦𝘳𝘴 #𝑒𝑠6 #strings #𝘤𝘰𝘥𝘦𝘳 #𝘱𝘳𝘰𝘨𝘳𝘢𝘮𝘮𝘦𝘳𝘴 #𝘫𝘰𝘣𝘴𝘦𝘦𝘬𝘦𝘳𝘴


To view or add a comment, sign in

More articles by Ajay Sharma

  • Javascript Interview - bind function

    The bind() function is a method available on all function objects in JavaScript.It returns a new function, where the…

Explore content categories