🧠 Hoisting - not a programming universal. Look at the following error of two different snippet in attached image👇 In JavaScript, behavior differs based on how variables are declared. Variables declared with var are hoisted and initialized with undefined, so accessing them before declaration does not throw an error. Variables declared with let and const are also hoisted but remain uninitialized in the Temporal Dead Zone, which is why accessing them before declaration throws a ReferenceError. In Python, variable declarations are not hoisted. The interpreter executes code line by line, from top to bottom. When print(message) runs, the variable message has not been created yet, so Python raises a NameError. Shortly: Python binds names only when their definition executes, while js hoists declarations and knows names before execution begin. 👉 Same intent, same flow, same mistake — different outcome due to different working behavior. #programming #Programming #JavaScript #javascript #Python #python #ProgrammingTips #learning #learn #tips
JavaScript vs Python Variable Hoisting
More Relevant Posts
-
Day 6 of my Python journey 🐍🚀 Day 6 is in the books! Today was a mix of handling errors gracefully and discovering some syntax that is completely unique to Python. Here is a breakdown of what I learned and how my Next.js/TypeScript brain processed it: 🛡️ Exception Handling (Try / Except / Finally): In JS, we use try...catch to stop bugs from crashing the whole app. Python uses try...except. The logic is exactly the same, including the finally block that runs no matter what. I also learned how to raise custom errors (just like throw new Error in JS). 🤯 Loops with else: Wait, loops can have an else statement?! This blew my frontend mind a little bit. In Python, an else block attached to a for or while loop will run only if the loop finishes naturally (without hitting a break). Very cool, but definitely takes getting used to! ⚖️ Shorthand If/Else: This is Python's version of the JS ternary operator (condition ? true : false). Instead of symbols, Python reads like plain English: result = True if condition else False. 🕵️♂️ Mini-Project: I put it all together by building a Secret Language Encoder/Decoder! It takes user input, manipulates the strings, and spits out an encrypted (or decrypted) message. The pieces are really coming together, and building actual logic feels great. 📈 #Python #LearningInPublic #SoftwareEngineering #FrontendDev #CodeWithHarry #100DaysOfCode
To view or add a comment, sign in
-
-
Code the Web. Power It with Python. HTML gives structure. CSS gives style. JavaScript gives interaction. But Python? Python gives logic, automation, data, and intelligence. This is where the web stops being static and starts becoming smart: • APIs that actually scale • AI features that solve real problems • Backends that connect everything together I stopped asking “Which language should I learn next?” and started asking “What can I build with what I know?” That shift changed everything. If you’re learning web development: 👉 Don’t chase tools 👉 Build projects 👉 Let Python power the web you create What’s one thing you’ve built (or want to build) with Python + Web? Drop it in the comments 👇
To view or add a comment, sign in
-
🐍 I built a Python Memory Puzzle Game — and it actually teaches you Python while you play! The idea was simple: what if a classic card-matching game could double as a learning tool? Every time you match a pair, you unlock a real Python fun fact — from how Guido van Rossum named the language after Monty Python 🎭, to why duck typing works the way it does 🦆. 🎮 What's in the game: → 16 cards / 8 Python-themed pairs → 3 difficulty levels (Easy → Hard) → Live timer, score, and move counter → Star ratings based on efficiency → Confetti bursts on every match 🎉 → 8 Python concepts covered with fun facts 🛠️ Tech used: → Pure HTML, CSS & vanilla JavaScript → Zero dependencies — one single file → CSS 3D card-flip animations → CSS Grid for responsive layout This was a fun challenge in keeping everything inside a single .html file while still making it feel polished and interactive. No React, no npm, no build step — just open in a browser and play. Whether you're a Python beginner looking for a fun way to learn, or just someone who enjoys a good memory challenge, give it a try! 🚀 Happy to share the code: https://lnkd.in/dgHTuTz5 #Python #WebDevelopment #HTML #CSS #JavaScript #LearningByDoing #OpenSource #100DaysOfCode #PythonProgramming #BuildInPublic #SoftGrowTech
To view or add a comment, sign in
-
Day 3 of my Python journey 🐍🚀 Today was all about logic and control flow. Day 3 focused on how Python makes decisions and repeats tasks. Here is a straightforward breakdown of today's concepts and how they compare to my daily TypeScript/JavaScript work: 🔀 Conditionals (If / Elif / Else): Python drops the parentheses () and curly braces {}. It also uses elif instead of else if. It takes a minute to get used to the indentation, but the code reads beautifully, almost like plain English. 🎯 Match Case: This is Python’s exact answer to the JavaScript switch statement! It makes handling multiple specific conditions much neater than writing a giant wall of if/else blocks. 🔁 Loops (For & While): While loops feel very similar to JS, the for loop in Python is wonderfully simplified. Instead of writing out for (let i = 0; i < 10; i++), Python just uses for i in range(10):. It is so much faster to type. 🛑 Break & Continue: The good news? These work exactly the same way they do in JavaScript to stop a loop or skip an iteration entirely. No mental translation needed here! The syntax is really starting to feel natural now. Progress is steady. 📈 #Python #LearningInPublic #SoftwareEngineering #FrontendDev #CodeWithHarry #100DaysOfCode
To view or add a comment, sign in
-
-
My Python RAG pipeline choked at 50 concurrent users. So I ripped out the orchestration layer and rebuilt it in Node.js. Unpopular opinion: Python is the king of training. But for serving? It’s too heavy. When you move from a Jupyter notebook to real-world WebSockets, things break. I didn't just need inference. I needed: • To handle 1,000+ concurrent embeddings. • Non-blocking streams. • Zero serialization headaches. Python’s GIL (Global Interpreter Lock) fought me every step. Node’s event loop ate the load for breakfast. The new stack: 1. Training: Python (obviously). 2. API/Orchestration: Node.js + TypeScript. 3. Vector DB: Pinecone. The result? 40% lower latency and no thread-blocking nightmares. Use the right tool for the layer, not just the language you learned first. What is the biggest bottleneck in your current stack? #VectorDatabase #RAG #Javascript
To view or add a comment, sign in
-
-
🐍 Python pass in Functions — Do Nothing (On Purpose) 🤫 Sometimes you need a function but don’t want to write its logic yet. Python doesn’t allow empty blocks — so we use pass 👇 ✅ Example: Empty Function def my_function(): pass ✔️ No error ✔️ Function does nothing ✔️ Useful as a placeholder 💡 Why pass is needed? Without it, Python will give an error ❌ def my_function(): 👉 This causes an IndentationError ✅ Real Example def login_system(): pass # Will implement later 👉 Program runs, but function has no behavior yet 🔥 Where pass is commonly used • When planning code structure • During development/testing • In empty classes, loops, or conditions • As a temporary placeholder 🔑 Simple Meaning: pass = “Skip for now, do nothing” 🚀 Small keyword, big usefulness — especially for clean development workflows. #Python #Coding #Programming #LearnToCode #Developer
To view or add a comment, sign in
-
Day 3 of 10: Python Control Flow & The Quirks of Iteration 🐍🔁 We are onto Day 3 of my Python sprint! Today’s focus from the CodeWithHarry handbook was all about conditional expressions and loops. Moving my backend logic from Node.js to Python is feeling smoother by the day. The pseudo-code nature of it—dropping the curly braces and relying entirely on clean indentation—makes writing complex logic incredibly fast. Here is what stood out to me today: 📌 Streamlined Conditionals: Trading else if for Python's elif. It’s a small syntax shift, but it makes chained conditional blocks read much cleaner. 📌 The range() Function: Iterating with for i in range() is a brilliantly efficient way to generate sequences and handle iterations compared to the traditional for (let i = 0; i < n; i++) we use in JS. 📌 The for...else Construct: This was today's biggest "Aha!" moment. Python actually allows you to attach an else block directly to a for loop. It only executes if the loop exhausts naturally without hitting a break statement. This is an amazing built-in tool for writing search algorithms without needing extra flag variables! All my practice scripts for today are already pushed to the tasks folder in my GitHub repo. Tomorrow, we get into Functions and Recursion! Python devs: How often do you actually use the for...else construct in your production AI or backend code? Is it a daily driver or a niche trick? Let’s discuss! 👇 #Python #SoftwareEngineering #BackendDevelopment #10DayChallenge #CodeWithHarry
To view or add a comment, sign in
-
-
When init isn't enough: The Python mistake that cost me 3 hours Found a junior dev hardcoding database connections inside every class method. Here's what we fixed: ❌ Before: Python class UserService: def get_user(self, id): db = connect_to_database() # 🔥 New connection every call return db.query(f"SELECT * FROM users WHERE id={id}") ✅ After: Python class UserService: def __init__(self, db_connection): self.db = db_connection # ♻️ Reuse connection def get_user(self, id): return self.db.query("SELECT * FROM users WHERE id=?", [id]) Dependency injection isn't just fancy talk - it's how you avoid 500 database connections crashing prod at 3am. What OOP concept made you facepalm when it finally clicked? #Python #SoftwareEngineering #CodingBestPractices #TechEducation #Programming
To view or add a comment, sign in
-
One of the most common Python mistakes I still see, especially in growing developers, is misunderstanding variable scope. It leads to code that runs but behaves unpredictably. And those are the hardest bugs to debug. Once I truly understood how Python handles local, global, and nonlocal variables, my code became easier to reason about and my debugging time dropped significantly. I wrote a short, practical guide explaining variable scope the way I wish it had been explained to me, with real examples. 👉 Read it here: https://lnkd.in/djp6HJdD #Python #LearnPython #SoftwareEngineering #DeveloperGrowth
To view or add a comment, sign in
-
🚨Errors in Code & Errors in Data When writing programs, errors generally come from two sides. 1️⃣ Errors in Code (Bugs) These happen because of mistakes made while writing the program. Wrong logic, incorrect conditions, syntax issues — all of these lead to unexpected behavior. This type of error is commonly called a bug. 👉 The problem is in the logic. 2️⃣ Errors in Data Sometimes the code is perfectly written — but the input data is wrong. Invalid values, missing fields, unexpected formats, or corrupted data can cause incorrect results or runtime failures. 👉 The problem is in the input, not the logic. 🛠️ So how do we handle them? That’s where exception handling comes in. Such as: In JavaScript → try...catch...finally In Python → try...except...finally #JavaScript #Python #WebDevelopment #SoftwareEngineering #Programming #Developers #Coding #TechCommunity #LearningInPublic #SoftwareDevelopment #TechLearning
To view or add a comment, sign in
-
More from this author
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