🚀 JavaScript Tip: Mastering Strings in JavaScript ✨

🚀 JavaScript Tip: Mastering Strings in JavaScript ✨

JavaScript offers three ways to work with strings:

1️⃣ Single Quotes (' ')

const name = 'Kavindu'; 
console.log('Hello, ' + name + '!');        

2️⃣ Double Quotes (" ")

const message = " I'm learning JavaScript. "; 
console.log(message);        

3️⃣ Template Strings (``)

  • Interpolation: Insert values directly into strings.

const items = 2;
const total = 28.94;
console.log(`Items (${items}): $${total}`);        

Output: Items (2): $28.94


  • Multi-line Strings: Create strings spanning multiple lines.

console.log(`This is a 
multi-line string.`);        

💡 Pro Tip: Use template strings for cleaner, more readable code!

#JavaScript #CodingTips #WebDevelopment

To view or add a comment, sign in

More articles by Kavindu Ushan

  • 🔒 Why Encapsulation Matters in Java

    When I started learning Java, I wondered: "Why do we need getters and setters? Why not just make fields public and…

  • What is Lazy loading?

    Lazy loading is a web development optimization technique that delays the loading of non-critical elements on a webpage…

    5 Comments
  • Migrating Swagger Configuration in Spring Boot 3.x with Java 21

    Spring Boot 3.x introduces several updates to modernize its framework, including a shift to the Jakarta namespace.

    1 Comment

Explore content categories