Day 65 – JavaScript String Methods Today I explored advanced JavaScript string methods that are commonly used for text validation, searching, formatting, and manipulation in real-world applications. Topics Covered: startsWith() – Checks whether a string begins with a specific value toUpperCase() – Converts all characters to uppercase toLowerCase() – Converts all characters to lowercase includes() – Verifies whether a specific value exists in a string search() – Finds the index position of a value (returns -1 if not found) concat() – Combines multiple strings in a defined order These methods are especially useful in form validation, search features, filtering data, and user input handling. Understanding them helps write cleaner, more efficient, and readable JavaScript code. #JavaScript #FrontendDevelopment #WebDevelopment #StringMethods
JavaScript String Methods: Validation, Searching, and Formatting
More Relevant Posts
-
Shallow Copy vs Deep Copy in JavaScript 👨💻 Understanding the difference can save you from unexpected bugs when working with objects. A shallow copy shares references, while a deep copy creates a fully independent clone. Choose wisely based on performance and data safety. 🚀 #JavaScript #WebDevelopment #FrontendDevelopment #ProgrammingBasics
To view or add a comment, sign in
-
-
🚀 Common Types of Errors in JavaScript While coding in JavaScript, you’ve probably seen errors in the console. Understanding them makes debugging much easier. Here are the most common types: 🔹 1. Syntax Error Occurs when the code breaks JavaScript rules. let a = ; // ❌ Missing value The code won’t run until the syntax is fixed. 🔹 2. Reference Error Occurs when trying to use a variable that doesn’t exist. console.log(x); // ❌ x is not defined 🔹 3. Type Error Occurs when an operation is performed on the wrong data type. let num = 10; num.toUpperCase(); // ❌ Not a string 🔹 4. Range Error Occurs when a value is out of the allowed range. let arr = new Array(-1); // ❌ Invalid array length 🔹 5. Logical Error The code runs, but the output is wrong. let total = 10 + "5"; console.log(total); // "105" ❌ Instead of 15 💡 Tip: • Syntax errors stop execution • Runtime errors crash execution • Logical errors give wrong results Understanding errors is the first step to becoming better at debugging. #JavaScript #WebDevelopment #FrontendDevelopment #CodingTips #Debugging
To view or add a comment, sign in
-
The this Keyword in JavaScript — It Depends on How You Call It One of the most misunderstood concepts in JavaScript is this. Not because it’s complicated — but because it behaves differently based on how a function is invoked. In regular functions, this is determined at call time. In arrow functions, this is determined at creation time (lexical binding). That means this does not refer to where the function is written. It refers to how the function is executed. This is why context gets “lost” in callbacks, event handlers, and extracted methods. Understanding this removes a huge category of subtle bugs in production code.
To view or add a comment, sign in
-
-
Debugging JavaScript nested for-loops with querySelector DOM manipulation involves checking your functions, arrays, syntax, variable declaration, and structure. That's a lot, even for simple functionality. The attached screenshot is the code (manually typed) that looks clean, but does not modify the HTML <li> content one bit. The error did not appear to be in the HTML side. Eventually I commented this code out and restarted, using different variable names, and the code produced the expected output. The issue might have been parameters or arguments not being called properly, or some other misspelling or missing/extra character.
To view or add a comment, sign in
-
-
In JavaScript, this = depends on how function is called.. let name = "Sohail Ansari"; const human = { name :"Sohail", greet : function(){ console.log("Hello ! " + this.name); } } human.greet() Output - Hello ! Sohail, because greet function has been called using human object. Here, this refer to the object human and it has name property with value "Sohail". let greetOutsite = human.greet; greetOutsite(); Now, function greetOutsite has been called independentally, in a global environment, so this keyword refer to the global object. The lexical environment of global object contain a variable - name with value Sohail Ansari. So output will be Hello ! Sohail Ansari
To view or add a comment, sign in
-
One habit that instantly improves JavaScript code quality: Avoid stacking too much logic inside a single condition. Instead of writing: if ( user && user.profile && user.profile.email ) { sendEmail( user.profile.email ); } Use optional chaining: if ( user?.profile?.email ) { sendEmail( user.profile.email ); } Cleaner and More readable. Optional chaining is not just shorter syntax. It changes how you think about data safety. #JavaScript #CleanCode #WebDevelopment
To view or add a comment, sign in
-
-
📌 Understanding parseInt() in JavaScript When working with user inputs, APIs, or form data, values often come as strings. To convert those string values into integers, JavaScript provides the parseInt() method. 👉 What does parseInt() do? 🔹 parseInt() converts a string into an integer number. 👉 In simple terms: It extracts a number from a string and converts it into an integer. 💠 Specifying the radix avoids unexpected behavior and ensures consistent results. 💠 Number() requires the entire string to be numeric. 💠 parseInt() extracts the integer part. ✅ Best Practice ✔ Always pass the radix (usually 10) ✔ Validate results using Number.isNaN() parseInt() is a simple yet powerful method that helps convert string data into usable integers — especially when handling user input or processing external data. #JavaScript #WebDevelopment #Frontend #CodingTips #LearnJavaScript
To view or add a comment, sign in
-
-
𝗧𝗵𝗲 𝗜𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝗰𝗲 𝗼𝗳 𝗧𝗵𝗲 "𝗧𝗵𝗶𝘀" 𝗞𝗲𝘆𝘄𝗼𝗿𝗱 𝗜𝗻 𝗝𝗮 v𝗮𝗦𝗰𝗿𝗶𝗽𝘁 A friend of mine failed a top tech interview due to one JavaScript question. The question was about thethis keyword. At first, it seemed simple. But it was designed to test the candidate's understanding of runtime binding in JavaScript. Here are the key rules to remember: -this is determined by how a function is called, not where it is defined. - Arrow functions do not have their own "this". They capture it from the surrounding scope. Let's look at an example: ``` is not allowed, so here is the example in plain text: const module = { x: 42, getX() { return this.x; }, getXLambda: () => this.x }; When you call module.getX(), "this" refers to the module object. But when you call module.getXLambda(), "this" refers to the global object. If you extract the function from the object and call it,this will refer to the global object. You can use the bind method to set the context of the function. Understanding these rules is crucial in JavaScript, especially when working with frameworks like React, Node.js, and Express. If you remember these two rules, debugging most "this" issues becomes much easier. Source: https://lnkd.in/gGy6R-_J
To view or add a comment, sign in
-
Today I solved a classic JavaScript problem: Removing duplicates from an array without using built-in methods like Set. Instead of relying on shortcuts, I implemented the logic manually using nested loops to fully understand how duplicate detection works internally. 🧠 Problem Given an array like: Copy code [1, 2, 2, 3, 4, 3] Return: [1, 2, 3, 4] 🔍 My Approach I created a new empty array called unique to store only distinct values. I looped through each element of the original array. For every element, I checked whether it already exists inside the unique array. If it does not exist, I pushed it into the unique array. If it already exists, I skipped it. This approach uses: An outer loop to iterate over the original array An inner loop to check for existing values A boolean flag (exists) to track duplicates 💡 Why I Chose This Approach While JavaScript provides a built-in way to remove duplicates using: [...new Set(arr)] I intentionally avoided it to: Strengthen my understanding of loops Improve my logical thinking Practice writing interview-style solutions Understand time complexity and algorithm behavior ⏱ Time Complexity O(n²) — because for each element, we may check the entire unique array. 🎯 Key Learning This problem helped me understand: Nested loop logic How duplicate detection works internally The importance of loop structure and placement Debugging mistakes like incorrect loop conditions Building strong fundamentals makes advanced concepts easier later. Consistency > shortcuts 💪 #JavaScript #ProblemSolving #WebDevelopment #100DaysOfCode #FrontendDeveloper #DSA #LearningInPublic
To view or add a comment, sign in
-
💡 Sunday Dev Tip: JavaScript Array Methods Stop writing loops. Use array methods instead! ❌ Traditional Loop: let doubled = []; for (let i = 0; i < numbers.length; i++) { doubled.push(numbers[i] * 2); } ✅ Modern Approach: const doubled = numbers.map(n => n * 2); Master These Methods: → .map() - Transform each element → .filter() - Keep elements that match → .reduce() - Calculate single value → .find() - Get first match → .some() / .every() - Test conditions Your code becomes: ✅ More readable ✅ Less error-prone ✅ Easier to maintain ✅ More functional Which array method do you use most? 💬 #JavaScript #CleanCode #WebDevelopment #CodingTips #ES6
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development