🧠 Thinking in Code: My JavaScript Problem-Solving Snapshot Today, I spent time focusing on how I think while coding, not just what I code. I chose a simple yet powerful JavaScript problem: 👉 Counting the number of vowels in a sentence Why this problem? Because it combines loops, condition checks, and clean logic, which are core fundamentals for any frontend or JavaScript developer. ✏️ Pseudo Code (Before Writing Any JS) Before touching the keyboard, I broke the logic down in plain English: Convert the sentence to lowercase Loop through each character Check if the character is a vowel Increase a counter when a vowel is found Writing this first made the actual coding much smoother. 💻 JavaScript Code function countVowels(str) { let count = 0; let vowels = "aeiou"; for (let i = 0; i < str.length; i++) { if (vowels.includes(str[i])) { count++; } } return count; } // Test cases console.log(countVowels("Hello World")); // 3 console.log(countVowels("JavaScript")); // 3 console.log(countVowels("AEIOU")); // ❌ Initially returned 0 🐞 What Went Wrong & How I Fixed It My function failed for uppercase vowels. Using console.log(), I quickly realized the comparison was case-sensitive. ✅ Fix applied: str = str.toLowerCase(); After adding this line, all test cases worked as expected. 💡 Key Takeaway (Aha Moment) This small exercise reminded me that: Good logic starts before writing code. Pseudo code + console.log() = faster debugging and clearer thinking. Even simple problems can teach big lessons about structure, clarity, and mindset. 📣 Let’s Learn Together How do you approach JavaScript problems? Do you write pseudo code first, or dive straight into coding? Would love to hear your process 👇 AlmaBetter #AlmaBetter #JavaScript #Debugging #ProblemSolving #FrontendBasics #CodeThinking #ISTJourney #LearningInPublic
JavaScript Vowel Counter: Problem-Solving with Pseudo Code
More Relevant Posts
-
Interviewer:- Explain Hoisting in Javascript. Answer:- JavaScript Hoisting refers to the process whereby the interpreter appears to move the declaration of functions, variables, classes, or imports to the top of their scope, prior to execution of the code.(MDN Defination) Hoisting is a core JavaScript behavior where declarations are processed before code execution. This means the JS engine scans the code first and allocates memory for variables and functions. 🔹 var Hoisting Variables declared with var are hoisted and initialized with undefined. You can access them before declaration, but the value won’t be available yet. 🔹 let & const Hoisting These are also hoisted, but not initialized. They exist in the Temporal Dead Zone (TDZ) until the declaration line is executed. Accessing them early throws a ReferenceError. 🔹 Function Hoisting Function declarations are fully hoisted, including their definitions, so they can be called before being defined. Function expressions and arrow functions follow variable hoisting rules. 🔹Arrow Function Hoisting in JavaScript Arrow functions are not hoisted like function declarations. Their hoisting behavior depends on how they are defined. 1. Arrow Functions with var The variable is hoisted and initialized as undefined, but the function is not. Calling it before assignment results in a TypeError. 2. Arrow Functions with let or const They are hoisted but remain in the Temporal Dead Zone (TDZ). Accessing them before initialization throws a ReferenceError. 🔹 Key Difference Unlike normal function declarations, arrow functions cannot be called before they are defined. 📌 Best Practice Always define arrow functions before using them to avoid unexpected runtime errors. 📌 Why it matters? Understanding hoisting helps prevent runtime errors, improves debugging, and leads to more predictable and maintainable JavaScript code. #JavaScript #JS #Hoisting #WebDevelopment #FrontendDevelopment #Frontend #Programming #Coding #Developer #SoftwareDevelopment #LearningToCode #Tech #CodeNewbie #100DaysOfCode #WebDev #ReactJS #NodeJS
To view or add a comment, sign in
-
I was working on a project that was built using JavaScript. Everything was going fine at first. But when the project reached its final stage and I started using JavaScript more heavily—pushing it closer to its limits—problems began to appear. At this stage, the application gradually became laggy and started hanging over time, especially when machine-level or low-level heavy processing was required. I tried various optimization techniques and did a lot of research, but I didn’t get any significant performance improvement. That’s when I realized the issue wasn’t just with the code—it was actually a language-level limitation. One of the biggest reasons is that JavaScript is fundamentally single-threaded. This model works very well for I/O-bound and event-driven applications, but when it comes to CPU-intensive tasks, it becomes a bottleneck for the system. While working on this project, I saw firsthand that even a short block on the main thread could slow down the entire system, freeze the UI, and ruin overall responsiveness. Although JavaScript provides abstractions like async/await, promises, and even worker threads, they still can’t fully overcome the core limitation of the main execution thread. When you try to perform low-level or machine-oriented tasks using JavaScript, the runtime cannot effectively utilize multiple CPU cores. From this experience, I clearly understood that for building low-level, high-performance systems, languages like Rust or C++ are far more suitable. These languages offer true multithreading, fine-grained memory control, and predictable performance—qualities that are critical for system-level work. JavaScript is undoubtedly a very powerful language and works excellently in many areas, especially for web and I/O-heavy applications. But after working on this project, I’ve seen its limitations with my own eyes—JavaScript is not a solution for every problem. Choosing the right tool for the right problem is what matters most. #javascript #engineering #coding
To view or add a comment, sign in
-
So, keywords are a big deal in JavaScript. They're like the secret language that JavaScript uses to get things done. You can't just use them for anything, or it's like trying to sit at a table that's already reserved for someone else - it's just not gonna work. Think about it, when you're coding, you're basically giving the computer a set of instructions, and keywords are like the commands that make it all happen. For instance, you useconst to create a constant value, like a fixed price that never changes - it's like setting a price tag that says "this is what it costs, no negotiations." And then there's "let", which creates a variable, like a price that can fluctuate based on demand - it's like a price tag that says "make an offer." And don't even get me started on decision making - that's where "if" and "else" come in, like a flowchart that helps the computer figure out what to do next. It's like, "if it's sunny, then go to the beach, else stay home and watch Netflix." Some other key keywords to keep in mind: - "function" creates a block of code that can be used again and again, like a recipe that you can follow to make your favorite dish. - "return" gives the result of a function, like the final answer to a math problem. The thing is, these keywords can be a bit tricky to use, and they can behave differently in different situations - it's like trying to navigate a maze, you gotta know the right turns to take. So, use them carefully, and make sure you understand how they work. Check out this article for more info: https://lnkd.in/d4s9vnnv #JavaScript #Coding #WebDevelopment
To view or add a comment, sign in
-
🧠 Hoisting in JavaScript – Concept Made Simple ⚡ Hoisting is one of those JavaScript concepts that feels confusing at first but becomes very logical once you understand what happens behind the scenes. JavaScript executes code in two phases: 1️⃣ Memory Creation Phase 2️⃣ Execution Phase Hoisting happens in the memory creation phase 👇 🟡 var Hoisting ✔ Declaration is hoisted ✔ Memory is allocated ✔ Value is set to undefined This is why variables declared with var can be accessed before their declaration — but their value isn’t available yet. ⚠️ This behavior often leads to unexpected bugs, which is why var is generally avoided today. 🔵 let & const Hoisting ✔ Declaration is hoisted ❌ NOT initialized in memory They exist in something called the Temporal Dead Zone (TDZ) 🛑 Accessing them before declaration results in an error. 👉 This makes let and const more secure and predictable than var. 🟢 Function Hoisting ✔ Function declarations are fully hoisted ✔ Stored completely in memory during creation phase This allows functions to be used before they appear in the code, making execution smoother. ⚠️ This applies only to function declarations, not function expressions. 🎯 Key Takeaways ✅ Hoisting is about memory allocation, not moving code ✅ var is hoisted with undefined ✅ let and const are hoisted but locked in TDZ ✅ Functions are fully available during execution Understanding hoisting = strong JavaScript foundation 💪 💡 Master the basics, and advanced JavaScript becomes easy 🔁 Share this with someone learning JS 📌 Save it for quick revision before interviews #JavaScript #Hoisting #JSConcepts #WebDevelopment #FrontendDeveloper #Programming #CodingBasics #LearnJavaScript 🚀
To view or add a comment, sign in
-
-
Today I explored one of the most powerful combinations in JavaScript: setTimeout() and Closures. I always knew about them, but now I truly understand how crucial they are in building asynchronous and dynamic applications. setTimeout() is not just a delay function. It shows how JavaScript handles: Asynchronous execution The event loop Non-blocking behavior Closures explain how functions remember their surrounding scope, even after execution is completed. When combined with setTimeout(), they form the foundation of many real-world features like timers, animations, background tasks, and delayed API calls. Example: function greet() { let name = "JavaScript"; setTimeout(function () { console.log(name); }, 2000); } greet(); Even after greet() finishes execution, the inner function still remembers name. That is the power of closure. Advantages: Enables asynchronous and non-blocking operations Makes delayed execution simple and effective Closures allow data privacy and memory persistence Essential for real-time features, animations, and background jobs Forms the backbone of callbacks and async programming Disadvantages / Cautions: Overuse of closures can increase memory usage Poor handling can lead to memory leaks Complex nested callbacks reduce readability Debugging asynchronous code requires strong fundamentals 💡 Key takeaway: setTimeout() shows when code runs. Closures decide what data that code can access. Together, they demonstrate how JavaScript manages time, memory, and execution context. Understanding this moves JavaScript from simple scripting to real engineering. This session helped me understand how asynchronous programming truly works internally and why closures are one of the most important concepts in JavaScript. #JavaScript #SetTimeout #Closures #AsyncProgramming #EventLoop #WebDevelopment #FrontendDevelopment #LearningJourney Write a JavaScript program that prints numbers from 1 to 5, where each number is printed after a delay equal to its value in seconds. Also, mention the expected output in the comment section.
To view or add a comment, sign in
-
-
⚙️ JavaScript – Prototypes & Classes Understanding Object-Oriented JavaScript JavaScript is not a class-based language by default. It uses prototypes to share properties and methods between objects. Understanding prototypes and classes helps you write structured, reusable, and scalable code. 🔹 What Is Prototypal Inheritance? Prototypal inheritance means objects can inherit properties and methods from other objects. Every JavaScript object has a hidden property that links it to another object called its prototype. 👉 This is how JavaScript achieves inheritance. 🔹 What Is __proto__? __proto__ is a reference to an object’s prototype. It points to the object from which properties are inherited Used internally by JavaScript Direct usage is not recommended (use Object.getPrototypeOf() instead) 👉 Through __proto__, JavaScript looks up properties in the prototype chain. 🔹 Prototype Chain When you access a property: JavaScript checks the object itself If not found, it checks its prototype Continues up the chain until null 👉 This chain is called the prototype chain. 🔹 Class Syntax (ES6) Classes are syntactic sugar over JavaScript’s prototype system. They provide a cleaner and more readable way to write object-oriented code. Under the hood, JavaScript still uses prototypes. 🔹 Constructor Method The constructor method is used to initialize object properties. Runs automatically when a new object is created Sets initial values Only one constructor per class 👉 Helps create multiple objects with similar structure. 🔹 Extending Classes (extends) The extends keyword is used to create a child class from a parent class. Child class inherits properties and methods Promotes code reuse Maintains a clean hierarchy 👉 This is inheritance using classes. 🔹 super Keyword super is used to call: Parent class constructor Parent class methods 👉 Must be called before using this in child constructors. 🧠 Simple Way to Remember Prototype → shared methods proto → link to prototype Prototype chain → lookup path class → cleaner syntax constructor → object initialization extends → inheritance super → parent access ✅ Why Prototypes & Classes Matter Core JavaScript interview topic Helps understand how objects really work Used heavily in frameworks like React Improves code organization and scalability Essential for object-oriented programming Without understanding prototypes, classes feel magical. With understanding, everything makes sense 🔥 Understand object-oriented JavaScript Mastering prototypes and classes builds a strong foundation for advanced JavaScript, frameworks, and backend development. . . #JavaScript #OOP #Prototypes #Classes #WebDevelopment #FrontendDevelopment #LearningInPublic #FullStackJourney
To view or add a comment, sign in
-
-
JavaScript Interesting Fact - Functions Are Objects ! In JavaScript, Functions are not just blocks of code - they are objects stored in memory. This means a function can have its own properties, can be assigned to variables, passed as arguments, and even returned from other functions. In the given example, a normal function is created and then a custom property is attached to it. when the function is called, it executes its logic, and when the property is accessed, it behaves just like an object property. This clearly shows that JavaScript treats functions as first-class objects. This concept play a crucial role in many core JavaScript features such as callbacks, higher-order functions, event handling, and modern frameworks like React. Understanding this behavior helps developers write more flexible, reusable, and powerful code. Key Takeaway ! In JavaScript, a function is both executable code and an object in memory. Mastering this concept makes advanced JavaScript patterns easier to understand and apply. GFG connect post link: https://lnkd.in/duMHbS8Z #JavaScript #WebDevelopment #Programming #FirstClassFunctions #SoftwareDevelopment #Coding #Tech #Developer #LearnJavaScript #ProgrammingConcepts
To view or add a comment, sign in
-
-
Why does 0 == false return true in JavaScript? 😵 If this confuses you, you're not alone. I wrote a guide explaining == vs === and how to avoid common pitfalls that trip up even experienced developers. Link below 👇 https://lnkd.in/dGP2aJZr #JavaScript #CodingTips #WebDev
To view or add a comment, sign in
-
Just deep dived into JavaScript closures, Closures are one of those core JavaScript concepts that can seem abstract at first, but once you understand them, they unlock a ton of expressive power in your code. In simple terms, a closure is when a function “remembers” the scope in which it was created even if that outer function has already finished executing. This allows the inner function to access variables from its parent scope long after the parent has returned. Here are a few things I learned from the article: ✅ Closures let you retain state in a function without using globals. ✅ They help you encapsulate private data great for building safer, cleaner abstractions. ✅ You can use them to simplify repetitive or configuration-based logic (like building a reusable fetch utility). ✅ While closures are powerful, overusing them can have performance implications since the enclosed variables stick around longer. Example use cases: 🔹 Creating factory functions 🔹 Emulating private variables 🔹 Writing modular and reusable code If you’re learning JavaScript (or even if you’ve been writing it for a while), really grasping closures will level up how you think about functions and scope. Highly recommend giving this article a read! 👇 https://lnkd.in/dUbSgtJy #javascript #webdevelopment #programming #coding #softwareengineering #tech
To view or add a comment, sign in
-
Top 10 JavaScript Tips and Tricks Every Developer Should Know Learn the top 10 JavaScript tips and tricks every developer should know to write cleaner, safer, and more reliable code. A deep practical guide by Nile Bits with real world examples and best practices... Learn more here: https://lnkd.in/dP4xegKV
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