𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 – 𝐏𝐚𝐫𝐭 𝟔 Hey everyone! I’m sharing the next part of the notes that I prepared when I was learning JavaScript. In these notes, I’ve explained everything in the easiest way possible. 𝗧𝗵𝗶𝘀 𝗽𝗮𝗿𝘁 𝗰𝗼𝘃𝗲𝗿𝘀: Variable Scope Hoisting 𝘄𝗵𝗮𝘁 𝗶𝘀 𝗮 𝗧𝗲𝗺𝗽𝗼𝗿𝗮𝗹 𝗗𝗲𝗮𝗱 𝗭𝗼𝗻𝗲 (𝗧𝗗𝗭)? The time between entering the scope and variable initialization is called the Temporal Dead Zone (TDZ). 𝘄𝗵𝗮𝘁 𝗶𝘀 𝗮 𝗦𝗰𝗼𝗽𝗲 𝗖𝗵𝗮𝗶𝗻? JavaScript uses a scope chain to resolve variables. If a variable is not found in the current scope, JavaScript looks for it in the outer scope, continuing until the global scope. Putting these notes out there to help anyone revising or strengthening their JS fundamentals. 𝗣𝗿𝗲𝘃𝗶𝗼𝘂𝘀 𝗣𝗮𝗿𝘁𝘀 Part 1: Js Fundamentals Link: https://lnkd.in/gZdba3ga Part 2: Js Operators Link: https://lnkd.in/gUYuHXSb Part 3: Js Conditional Statements Link: https://lnkd.in/gWTfwkBr Part 4: Loops Link: https://lnkd.in/gUjuB5eY Part 5: Functions Link: https://lnkd.in/gQZadrza Hope this helps Feel free to share with your friends, and please comment your suggestions or doubts. #javascript #webdevelopment #programming #developers #learningbysharing #tech #learninpublic #cse #learninpublic
Siva Chandra Sekhar G’s Post
More Relevant Posts
-
JavaScript Algorithm Practice: Generating Prime Numbers Today, I worked on a classic algorithm problem in JavaScript: generating prime numbers up to a given limit. 🔹 Step 1: Create a helper function isPrime(n) It checks whether a number is prime by testing divisibility up to √n, which improves performance. 🔹 Step 2: Use this helper to build generatePrimes(number) This function loops from 2 up to the given number and collects all prime numbers. 📌 Key takeaways Breaking a problem into small reusable functions Optimizing loops using mathematical insights (√n) Writing clean and readable code I’m consistently practicing JavaScript fundamentals and algorithms to strengthen my problem-solving skills. 👉 Check out more JavaScript exercises here: 🔗 https://lnkd.in/ej4fNeZs #JavaScript #Algorithms #ProblemSolving #CodingPractice #WebDevelopment #LearningInPublic #GitHub
To view or add a comment, sign in
-
-
Why does this code run in O(n²) instead of O(n)? 🤔 I explored 3 ways to reverse a string in JavaScript and discovered a hidden performance trap that most beginners miss. Full breakdown 👇 https://lnkd.in/dqpAu7jX #JavaScript #DSA #WebDevelopment
To view or add a comment, sign in
-
🧠 JavaScript doesn’t break because of shortcuts. It breaks when fundamentals aren’t fully understood. I once tried using throw new Error() inside a ternary operator, expecting it to behave like a simple if/else. ❌ That didn’t work. 🧠 Why this happens (important detail): • throw is a statement, not an expression • Ternary operators only allow expressions It’s a tiny syntax rule — but a big “aha” moment. 💡 What this reinforced for me: ✔️ Fundamentals matter more than clever tricks ✔️ JavaScript prefers clarity over shortcuts ✔️ Small misunderstandings can lead to long debugging sessions These little details often separate code that runs from code that’s reliable. 👀 Your turn: What’s the smallest JavaScript mistake that once cost you the most time? 💬 Drop it in the comments — let’s learn from each other. #JavaScript #NodeJS #WebDevelopment #SoftwareEngineering #CodingLife #DeveloperLearning #CleanCode #Debugging #ProgrammingTips #TechCommunity #BuildInPublic
To view or add a comment, sign in
-
-
Most developers think they understand Hoisting.🙄 But ask them this: If let and const are hoisted then why does JavaScript throw a ReferenceError? 🤔 And here’s the bigger question: Why does var attach to window but let doesn’t? This is not beginner syntax anymore. This is about how the JavaScript engine actually prepares memory before execution. If you truly understand: • Memory Creation Phase • Global Execution Context • Temporary Dead Zone I’ve broken this concept down visually in a simple way. 🎯 Full breakdown is on my Instagram → @JswithDhruv Let’s build JavaScript fundamentals the right way. 📌 Save this for revision. Post Link: https://lnkd.in/dzUhxnNN #JavaScript #Programming #LearnToCode #ReactJs #connections #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 var vs let vs const in JavaScript If you’re learning JavaScript (or revising fundamentals), understanding these three is a must 👇 🔹 var 1. Function-scoped 2. Can be redeclared & reassigned 3. Hoisted (initialized as undefined) 4. Can cause unexpected bugs 🔹 let 1. Block-scoped {} 2. Can be reassigned, but not redeclared in the same scope 3. Safer than var 🔹 const 1. Block-scoped {} 2 . Cannot be reassigned 3. Must be initialized at declaration 4. Best choice by default ⚠️ Important note: const user = { name: "Alex" }; user.name = "Sam"; // This is allowed const prevents reassignment, not mutation (especially for objects & arrays stored in heap memory). 💡 Best practices: Use const by default Use let when reassignment is needed Avoid var in modern JavaScript 📌 Mastering basics = writing cleaner, bug-free code. #JavaScript #WebDevelopment #ProgrammingBasics #Frontend #LearningToCode
To view or add a comment, sign in
-
🗓️Day 38 of 100 - Why Does JavaScript Feel So Confusing? 🤯 If you’ve ever felt lost while learning JavaScript, trust me — you’re not alone. At first, JavaScript feels unpredictable: "5" + 1 // "51" "5" - 1 // 4 Same values. Different results. No error. 😅 Then there’s this: "5" == 5 // true "5" === 5 // false Small symbols. Big confusion. But here’s the truth 👇 JavaScript isn’t broken. It’s flexible. JavaScript: • Automatically converts types • Allows dynamic values • Follows hidden execution rules • Handles async work behind the scenes Once I stopped asking ❌ “Why is JavaScript so weird?” and started asking ✅ “What rule is JavaScript following?” Things slowly began to make sense. Feeling confused doesn’t mean you’re bad at coding. It means you’re learning a powerful language. One concept at a time. One bug at a time. It gets better. 💪✨ #JavaScript #WebDevelopment #LearningJourney #100DaysOfCode #Programming
To view or add a comment, sign in
-
-
You’ve probably seen this error many times in JavaScript: “SyntaxError: Unexpected token...” It’s so common that most of us just fix the typo and move on. But have you ever wondered why the error specifically mentions a “𝙩𝙤𝙠𝙚𝙣”? Here’s what’s really happening under the hood: Before JavaScript executes your code, the engine first splits the source into small pieces called tokens - keywords, identifiers, numbers, operators, brackets, and punctuation. Next, those tokens are parsed into a structured representation called an AST (Abstract Syntax Tree). This tree is what the JS engine actually uses to understand and run your program. For example, even a simple line like: 𝗹𝗲𝘁 𝗮 = 𝟭𝟬; becomes a full tree structure in the parser (you can see this in the attached AST). If any token appears where the grammar doesn’t allow it, the tree cannot be formed. And that’s the exact moment JavaScript stops and reports: 𝘜𝘯𝘦𝘹𝘱𝘦𝘤𝘵𝘦𝘥 𝘵𝘰𝘬𝘦𝘯. So a small missing bracket or extra comma isn’t just a typo - it’s the parser failing to construct a valid program from the token stream. #JavaScript #WebDevelopment #Programming #Debugging #SoftwareEngineering #JSInternals
To view or add a comment, sign in
-
-
✨ Understanding var, let, and const in JavaScript ✨ One of the first hurdles for beginners in JavaScript is figuring out when to use var, let, or const. While they all declare variables, the differences matter for clean, bug-free code: 🔹var – Function-scoped, allows redeclaration, and can lead to unexpected behavior due to hoisting. Best avoided in modern code. 🔹 let – Block-scoped, can be updated but not redeclared in the same scope. Ideal for variables whose values change over time. 🔹 const – Block-scoped, must be initialized at declaration, and cannot be reassigned. Perfect for constants or values that should remain fixed. Mastering these keywords is a small step that makes a big difference in writing clean, predictable, and modern JavaScript🚀 #JavaScript #WebDevelopment #FrontendDevelopment #CodingTips #LearnToCode #CleanCode #DeveloperLife #TechCommunity
To view or add a comment, sign in
-
Today I solved a Codewars #JavaScript challenge that looks simple on the surface but reinforces some really important fundamentals. The challenge: Write a function that takes an array of 10 digits (0–9) and returns them formatted as a phone number: (123) 456-7890 💡 My Approach I broke the problem down into three logical parts, just like an actual phone number: Area code -> first 3 digits Prefix -> next 3 digits Line number -> last 4 digits Using JavaScript’s slice() method, I extracted each segment from the array, converted them to strings using join(''), and then combined everything with a template literal to match the required format. This made the solution: 1. Readable 2. Easy to debug 3. Logically aligned with the problem statement ✅ Was this the best approach? For this specific challenge — yes. Why? The input size is fixed (always 10 digits), so performance concerns are minimal. slice() and join() are clear and expressive, which matters in real-world codebases. The solution prioritizes clarity over cleverness, something I’m learning to value more as I grow as an engineer. That said, in scenarios involving very large datasets, repeatedly slicing arrays could be inefficient. In those cases, approaches like iterating once or using string builders may scale better. Context always matters. 📚 What I learned Simple problems are great opportunities to practice clean thinking Readability is just as important as correctness. Knowing why an approach works is more valuable than just making it pass I’m consistently using Codewars to sharpen my JavaScript fundamentals and improve how I think about problem-solving. #JavaScript #Codewars #ProblemSolving #LearningInPublic #SoftwareEngineering #CleanCode #Developers
To view or add a comment, sign in
-
-
𝙏𝙝𝙞𝙨 𝙅𝙎 𝙩𝙧𝙞𝙘𝙠 𝙞𝙨 𝙛𝙖𝙨𝙩𝙚𝙧 𝙩𝙝𝙖𝙣 𝙈𝙖𝙩𝙝.𝙛𝙡𝙤𝙤𝙧( )… 𝙗𝙪𝙩 𝙙𝙤 𝙮𝙤𝙪 𝙙𝙖𝙧𝙚 𝙪𝙨𝙚 𝙞𝙩? As a JavaScript dev, you’ve probably used Math.floor() thousands of times. But there’s a sneaky alternative: ~~x ~~x can be faster than Math.floor(x) because it uses a bitwise trick at the engine level, skipping some of the overhead of a function call. But here’s the catch: it only works safely within the 32-bit signed integer range and behaves differently for very large numbers and some edge cases. So should you use it? Use Math.floor() for clarity and reliability in production. Use ~~x only when you fully understand its limits and have benchmarked your hotspot code. Sometimes “clever” JavaScript makes code harder to read than it needs to be. 𝙒𝙤𝙪𝙡𝙙 𝙮𝙤𝙪 𝙪𝙨𝙚 ~~ 𝙞𝙣 𝙮𝙤𝙪𝙧 𝙤𝙬𝙣 𝙘𝙤𝙙𝙚? 👇 #javascript
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