<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rahma Sameh</title>
    <description>The latest articles on DEV Community by Rahma Sameh (@rahma_sameh_4d4e2d51aeb75).</description>
    <link>https://dev.to/rahma_sameh_4d4e2d51aeb75</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2899041%2F026c7f71-48dd-4385-9eed-6cb0bf815065.png</url>
      <title>DEV Community: Rahma Sameh</title>
      <link>https://dev.to/rahma_sameh_4d4e2d51aeb75</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rahma_sameh_4d4e2d51aeb75"/>
    <language>en</language>
    <item>
      <title>Day 1: Mastering JavaScript Template Literals</title>
      <dc:creator>Rahma Sameh</dc:creator>
      <pubDate>Wed, 26 Feb 2025 10:00:26 +0000</pubDate>
      <link>https://dev.to/rahma_sameh_4d4e2d51aeb75/day-1-mastering-javascript-template-literals-192c</link>
      <guid>https://dev.to/rahma_sameh_4d4e2d51aeb75/day-1-mastering-javascript-template-literals-192c</guid>
      <description>&lt;p&gt;🚀 Welcome to Day 1 of my 100-day web development challenge! &lt;/p&gt;

&lt;p&gt;Today, we’re diving into template literals—one of JavaScript’s most useful features for handling strings dynamically.  &lt;/p&gt;

&lt;p&gt;What Are Template Literals?&lt;/p&gt;

&lt;p&gt;Template literals are a modern way to work with strings in JavaScript. Unlike regular strings, they:  &lt;/p&gt;

&lt;p&gt;✅ Use backticks (&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;/code&gt;) instead of quotes (&lt;code&gt;""&lt;/code&gt; or &lt;code&gt;''&lt;/code&gt;).&lt;br&gt;&lt;br&gt;
✅ Support multi-line strings without needing &lt;code&gt;\n&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
✅ Allow embedded expressions using &lt;code&gt;${}&lt;/code&gt; (known as string interpolation).  &lt;/p&gt;

&lt;p&gt;Why Are They Useful?&lt;br&gt;&lt;br&gt;
1️⃣ Easier String Concatenation &lt;br&gt;
Before template literals:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = "Rahmeh";
const message = "Hello, " + name + "! Welcome to JavaScript.";
console.log(message);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With template literals:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = "Rahmeh";
const message = `Hello, ${name}! Welcome to JavaScript.`;
console.log(message);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Cleaner and more readable! &lt;/p&gt;

&lt;p&gt;2️⃣ Multi-Line Strings Without &lt;code&gt;\n&lt;/code&gt; &lt;br&gt;
Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const oldWay = "Hello!\nWelcome to JavaScript.\n Let's learn together!";
console.log(oldWay);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With template literals:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const newWay = `Hello!
Welcome to JavaScript.
Let's learn together!`;
console.log(newWay);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ No need for &lt;code&gt;\n&lt;/code&gt; or string concatenation! &lt;/p&gt;

&lt;p&gt;3️⃣ Expression Evaluation Inside Strings&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = 10;
const b = 5;
console.log(`The sum of ${a} and ${b} is ${a + b}.`); 
// Output: The sum of 10 and 5 is 15.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Perform calculations and insert values dynamically.  &lt;/p&gt;

&lt;p&gt;🚀 Challenge of the Day: &lt;br&gt;
Now that we understand template literals, let's apply them!  &lt;/p&gt;

&lt;p&gt;💡 Challenge: Write a program that:&lt;br&gt;&lt;br&gt;
🔹 Asks the user for their name and age.&lt;br&gt;&lt;br&gt;
🔹 Calculates how many years until they turn 100.&lt;br&gt;&lt;br&gt;
🔹 Displays a friendly message using template literals.  &lt;/p&gt;

&lt;p&gt;Example Output:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Hello, Rahmeh! You are 25 years old. You will turn 100 in 75 years.&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Starter Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = prompt("What is your name?");
const age = prompt("How old are you?");
const yearsTo100 = 100 - age;

console.log(`Hello, ${name}! You are ${age} years old. You will turn 100 in ${yearsTo100} years.`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📝 What’s Next?&lt;br&gt;&lt;br&gt;
✅ Try modifying the program to handle invalid inputs.&lt;br&gt;&lt;br&gt;
✅ Add a simple HTML form instead of &lt;code&gt;prompt()&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
✅ Experiment with multi-line template literals.  &lt;/p&gt;

&lt;p&gt;Stay tuned for Day 2, where we explore javaScript conditionals and make this program even smarter!  &lt;/p&gt;

&lt;p&gt;💬 What’s your favorite use case for template literals?&lt;br&gt;
Drop a comment! 🚀  &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>templateliteral</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
