JAVASCRIPT Tea Episode 1: Javascript Keywords As part of my learning journey in JavaScript, I explored some key keywords and why certain practices are better avoided. JavaScript is the language that brings websites to life, making them interactive, dynamic, and responsive to user actions. At its core, it has a set of keywords that act like the building blocks of your code. They control logic, manage variables, and guide how data flows. Knowing how these keywords work is essential for writing code that’s not just functional, but clean, predictable, and easy to maintain. Here are 15 JavaScript keywords and what they do: 1. let – declares a block-scoped variable. Safer than var. 2. const – declares a constant variable that cannot be reassigned. 3. var – declares a function-scoped variable (older practice, less recommended). 4. if – runs code when a condition is true. 5. else – runs code when the if condition is false. 6. switch – evaluates an expression and runs code based on cases. 7. case – defines a block in a switch. 8. default – fallback code in a switch. 9. for – loop that runs code a set number of times. 10. while – loop that runs as long as a condition is true. 11. function – declares a reusable block of code. 12. return – exits a function and optionally returns a value. 13. break – exits a loop or switch immediately. 14. continue – skips the current loop iteration. 15. try / catch – handles errors; try runs code, catch handles errors. I also learned why using var to declare variables is discouraged in modern Javascript: 1. It is function-scoped, not block-scoped, which can cause unexpected behavior. 2. Hoisting can lead to variables being used before they are declared. 3. You can accidentally redeclare the same variable in the same scope. 4. It makes code less predictable and harder to maintain. Understanding these basics makes writing cleaner, safer, and more efficient JavaScript code. #JavaScript #WebDevelopment #Programming #TechLearning #Coding #SoftwareDevelopment The Curve Africa
JavaScript Keywords: A Beginner's Guide to let, const, var, and more
More Relevant Posts
-
So JavaScript is getting a whole lot more interesting. It's evolving, and fast. You can already play with some of these new features in the latest JavaScript engines - they're like the beta testers of the coding world. But here's the thing: these features aren't officially part of the standard yet, so you gotta be careful. Experimental features are like the secret menu at your favorite restaurant - they're not always on the menu, but they can be super useful if you know how to order them. For instance, there's Top-Level Await, which lets you use await in modules without needing async functions - it's like being able to get your food without waiting in line. And then there's Private Class Fields, which helps you encapsulate class properties, like keeping your secret recipe, well, secret. Logical Assignment Operators are another cool one - they simplify coding patterns, making it easier to write clean code. Oh, and let's not forget WeakRefs and FinalizationRegistry, which let you set references to objects that can be garbage-collected - it's like having a cleaning crew for your code. When you're using these experimental features, you gotta stay on top of things - proposed features can change, and that can break your existing code. It's like building a house on shifting sand - you need to be prepared for things to move. So, to use these features safely, you should always check browser compatibility - don't assume everyone's on the same page. Use polyfills and transpilation for unsupported features, like a translator for your code. And test those edge cases with frameworks like Jest or Mocha - it's like having a safety net for your code. Check out this article for more info: https://lnkd.in/gz8tXVm5 #ExperimentalFeatures #CodingBestPractices #ECMAScript #ProductionCode
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 focused on strengthening my core understanding of JavaScript fundamentals: Functions in JavaScript In JavaScript, functions are not just blocks of reusable code — they are first-class objects. About Function : Functions can be stored in variables. They can be passed as arguments to other functions. They can be returned from functions. They can be stored inside objects. JavaScript provides multiple ways to define functions, and each behaves slightly differently in terms of hoisting, scope, and the handling of the this keyword. How Objects Are Created in JavaScript An object in JavaScript is a collection of key-value pairs used to store structured data. Objects can be created using: Object literals Constructor functions Classes (ES6) Factory patterns Object.create() Regardless of the method used, internally JavaScript treats objects as reference types stored in memory. How Objects Work Internally (Memory Concept) Understanding memory allocation changes everything. JavaScript uses two main memory areas: • Stack • Heap Primitive values are stored directly in the stack. Objects, arrays, and functions are stored in the heap. When you assign an object to a variable, the variable does not store the object itself. Instead, it stores a reference (memory address) that points to the location in the heap. Equality in JavaScript: == vs === JavaScript provides two main equality operators. == (Loose Equality): Compares values after performing type coercion. Automatically converts data types when needed. === (Strict Equality): Compares both value and data type. No type conversion happens. Grateful to Sheryians Coding School and Anshu Pandey for emphasizing fundamentals over shortcuts. Strong basics in JavaScript make frameworks much easier to understand later. Building depth before speed. #JavaScript #WebDevelopment #LearningInPublic #SheryiansCodingSchool #AnshuPandey #FrontendDevelopment #Programming #JSFundamentals #ExecutionContext
To view or add a comment, sign in
-
-
While learning JavaScript, I noticed something that felt really strange at first. If you create a variable without using let, var, or const, JavaScript doesn’t throw an error. Instead… it silently creates a new variable What’s even more surprising is that this variable can be accessed outside the block where it was written. So how does this happen? When the JavaScript engine encounters a variable, it first checks the current block scope. If it doesn’t find it, it keeps going up through the parent scopes. If the variable is still not found, JavaScript creates it in the global scope, making it accessible everywhere. This behavior comes from the early philosophy of JavaScript. The language was designed to be forgiving and flexible, to help developers build web pages quickly without strict rules getting in the way. But this flexibility comes at a cost. Accidentally creating global variables can lead to: Data leaking between parts of the app Hard-to-track bugs Conflicts between scripts Once developers realized how dangerous this could be, Strict Mode was introduced: Js "use strict"; With strict mode enabled, JavaScript throws an error when you try to use an undeclared variable, preventing this silent leakage. This was a great reminder for me that JavaScript’s “weird” behaviors usually have historical reasons behind them — and understanding those reasons makes you a better developer, not just a user of the language. #JavaScript #JS #LearningJoureny #Web #SWE #coding
To view or add a comment, sign in
-
-
One thing I really wish someone had explained to me earlier about JavaScript. Most people start learning JS by memorizing: - variables - loops - if/else - functions And that's fine. until you start building real applications. That's when a different question shows up: "Why is my code not running in the order I wrote it?" For example: In the carousel, look at the 2nd Image code block. What would you expect to see? 🔹Most beginners say: A → B → C 🔹But JavaScript actually prints: A → C → B And the reason is something called the event loop. In simple terms: JavaScript runs all synchronous code first. Async tasks (like setTimeout, API calls, promises) wait in a queue. Only after the main stack is empty does JS go back and run them. This tiny concept explains so many things: - why API data arrives later why React state updates feel "delayed" - why async/await works the way it does Honestly, understanding this one idea made JavaScript feel much less "magical" and much more logical for me. And that's why I believe: - Before learning frameworks like React or Next.js, - make sure you understand how JavaScript actually executes. - I'm curious: Did you already know this setTimeout behavior? And what part of JavaScript still confuses you the most right now? 🔹Let's talk
To view or add a comment, sign in
-
🚀 JavaScript Learning – Functions & Arrow Functions Today I spent time practicing functions in JavaScript and then rewrote the same logic using arrow functions to really see the difference. Functions help avoid repeating code and keep logic organized. Once you get comfortable with them, writing JS feels much cleaner. Norma function example: function calculateSum(a, b) { return a + b; } let result1 = calculateSum(5, 3); console.log(result1); Then I converted the same logic into an arrow function: const calculateSum = (a, b) => a + b; let result2 = calculateSum(10, 7); console.log(result2); Same output, less code. Arrow functions feel simpler for small tasks, while normal functions are still useful in many cases. Practicing by rewriting code is helping things click much faster 💻🔥 #JavaScript #FrontendDevelopment #WebDevelopment #CodingJourney #LearningInPublic #DeveloperLife
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
-
🚀 MERN Stack Series – Day 10 Today, I learned an important JavaScript concept related to asynchronous programming — Callbacks vs Promises vs Async/Await. 📌 Why Asynchronous JavaScript? JavaScript is single-threaded, but async programming helps handle: API calls File operations Timers Background tasks 🔹 1️⃣ Callbacks A callback is a function passed as an argument to another function and executed later. ✔ Simple to use ❌ Can lead to callback hell ❌ Hard to read and maintain 🔹 2️⃣ Promises A Promise represents a value that may be available now, later, or never. States: Pending Fulfilled Rejected ✔ Better readability ✔ Better error handling than callbacks 🔹 3️⃣ Async / Await async/await is built on top of promises and makes async code look synchronous. ✔ Clean and readable code ✔ Easy error handling using try...catch ✔ Most preferred in modern JavaScript 💡 Best Practice ✔ Avoid callbacks for complex logic ✔ Use Promises or Async/Await ✔ Prefer Async/Await for clean and maintainable code Understanding async JavaScript is essential for working with APIs and real-world applications 🚀 #JavaScript #AsyncAwait #Promises #Callbacks #MERNStack #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
Explore related topics
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
This is insightful 👏