Exploring Strings in JavaScript: Key Concepts and Methods

Today, I explored Strings in JavaScript — one of the most common and powerful data types we use to handle text. Strings are sequences of characters enclosed in quotes (' ', " ", or ` `). Let’s dive into some key concepts 1. Creating Strings let single = 'Hello'; let double = "World"; let template = `Hello, World!`; 🔹 2. String Concatenation Joining multiple strings together: let firstName = "John"; let lastName = "Doe"; let fullName = firstName + " " + lastName; console.log(fullName); // John Doe You can also use template literals for cleaner syntax: let fullName2 = `${firstName} ${lastName}`; console.log(fullName2); // John Doe String Length let text = "JavaScript"; console.log(text.length); // 10 Accessing Characters let word = "Code"; console.log(word[0]); // C console.log(word.charAt(2)); // d Common String Methods let message = " Hello JavaScript! "; console.log(message.toUpperCase()); // " HELLO JAVASCRIPT! " console.log(message.toLowerCase()); // " hello javascript! " console.log(message.trim()); // "Hello JavaScript!" console.log(message.includes("Java")); // true console.log(message.replace("Hello", "Hi")); // " Hi JavaScript! " Splitting and Joining Strings let sentence = "I love JavaScript"; let words = sentence.split(" "); // ["I", "love", "JavaScript"] console.log(words.join("-")); // "I-love-JavaScript" Key takeaway: Strings are everywhere — from user inputs to API responses. Understanding string methods will make your JavaScript code more efficient and expressive. #100DaysOfCode #JavaScript #CodingChallenge #WebDevelopment #LearnInPublic #CodeNewbie

To view or add a comment, sign in

Explore content categories