Day -02 JavaScript Core concepts 🚀 JavaScript Fundamentals Every Developer Should Know Strong basics make advanced concepts easier. Here’s a quick revision 👇 🔹 Scope – Defines where variables are accessible. function test() {let x = 10}; console.log(x); // ❌ Error 🔹 TDZ (Temporal Dead Zone) – let & const cannot be accessed before initialization. console.log(a); // ❌ ReferenceError let a = 5; 🔹 Closure – A function remembers its outer scope. function outer() { let count = 0; return () => ++count}; 🔹 Callback – A function passed into another function. function greet(name, cb) { console.log("Hello " + name); cb()}; 🔹 Pass-by-Value let num = 10; function change(x){ x = 20; } change(num); console.log(num); // 10 🔹 Truthy & Falsy Boolean(0); // false Boolean([]); // true == vs === 5 == "5"; // true 5 === "5"; // false 💡 Master these core concepts, and JavaScript becomes much easier. #JavaScript #WebDevelopment #Frontend #Programming #JSInterview
Mastering JavaScript Fundamentals for Web Development
More Relevant Posts
-
💡 Understanding Scope in JavaScript One of the most important concepts in JavaScript is Scope. Scope defines where variables can be accessed in your code. There are three main types of scope in JavaScript: 🔹 Global Scope Variables declared outside any function are accessible anywhere in the program. let name = "Muneeb"; function showName() { console.log(name); } showName(); // Accessible because it's global 🔹 Function Scope Variables declared inside a function can only be used inside that function. function greet() { let message = "Hello"; console.log(message); } greet(); // console.log(message); ❌ Error 🔹 Block Scope Variables declared with "let" and "const" inside "{ }" are only accessible within that block. if (true) { let age = 25; console.log(age); } // console.log(age); ❌ Error 📌 Understanding scope helps developers write cleaner code and avoid bugs related to variable access. Mastering these fundamentals makes JavaScript much easier to understand and improves problem-solving skills. #JavaScript #WebDevelopment #FrontendDeveloper #Coding #LearnToCode
To view or add a comment, sign in
-
🚀 Understanding Closures in JavaScript Closures are one of the most powerful concepts in JavaScript, and they often appear in interviews for frontend or full-stack developer roles. 📌 What is a Closure? A closure happens when a function remembers the variables from its outer scope even after the outer function has finished executing. In simple words: A function can access variables from its parent function even after the parent function is done running. 💻 Example: function outerFunction() { let count = 0; function innerFunction() { count++; console.log(count); } return innerFunction; } const counter = outerFunction(); counter(); // 1 counter(); // 2 counter(); // 3 Here, innerFunction forms a closure because it remembers the count variable from outerFunction. ⚡ Why Closures are Useful Closures are commonly used for: • Data privacy • Creating private variables • Function factories • Event handlers • Callbacks and asynchronous code 📦 Real-world example: Closures are used in many libraries and frameworks like React for handling state and callbacks. 🧠 Key Takeaway A closure allows a function to retain access to its lexical scope, even when the function is executed outside that scope. If you’re learning JavaScript deeply, understanding closures will unlock many advanced patterns. 💬 What JavaScript concept confused you the most when you first learned it? #javascript #webdevelopment #frontenddevelopment #coding #programming #reactjs #100DaysOfCode
To view or add a comment, sign in
-
-
JavaScript Practice – Find Even Numbers Today I practiced a simple JavaScript program to find even numbers from an array. Question: Write a function to find even numbers from an array. Code: function evenNumbers(arr){ return arr.filter(function(num){ return num % 2 === 0; }); } console.log(evenNumbers([1,2,3,4,5,6])); Output: [2,4,6] Explanation: • filter() – Creates a new array based on a condition • num % 2 === 0 – Checks if the number is even • Returns only even numbers from the array I am currently learning Frontend Development and practicing JavaScript programs daily. #javascript #frontenddeveloper #codingpractice #webdevelopment #learning
To view or add a comment, sign in
-
-
💡 7 JavaScript Tricks I Wish I Knew Earlier....? JavaScript tricks that can save you hours of coding 👇 1️⃣ Convert string → number "const num = +"42"" Cleaner than "Number()" and super quick. --- 2️⃣ Remove duplicates from an array "const unique = [...new Set([1,2,2,3])]" No loops. No libraries. --- 3️⃣ Swap variables instantly "[a, b] = [b, a]" No temporary variable needed. --- 4️⃣ Convert any value to boolean "const isTrue = !!value" A simple trick used everywhere in JS codebases. --- 5️⃣ Flatten arrays "const flat = [1,[2,3]].flat()" Nested arrays? Not a problem anymore. --- 6️⃣ Optional chaining (no more undefined errors) "user?.profile?.name" Your app won't crash if something is missing. --- 7️⃣ Default values using ?? "const name = userName ?? "Guest"" Only uses "Guest" if the value is null or undefined. --- 💬 Be honest… How many did you already know? 1️⃣ – Just started learning 3️⃣ – Pretty comfortable with JavaScript 5️⃣ – Advanced developer 7️⃣ – JavaScript ninja 🥷 Comment your number 👇 ♻️ Save this post so you don’t forget these tricks. Follow for more JavaScript tips every week 🚀 #javascript #webdevelopment #frontend #coding #programming #softwaredevelopment
To view or add a comment, sign in
-
5 JavaScript Array methods every developer must know 👇 1️⃣ map() Transform every element in an array const doubled = [1,2,3].map(x => x * 2) // [2, 4, 6] ✅ 2️⃣ filter() Remove elements you don't need const evens = [1,2,3,4].filter(x => x % 2 === 0) // [2, 4] ✅ 3️⃣ reduce() Combine all elements into one value const sum = [1,2,3].reduce((acc, x) => acc + x, 0) // 6 ✅ 4️⃣ find() Get first matching element const user = users.find(u => u.id === 1) // { id: 1, name: "Shivesh" } ✅ 5️⃣ some() & every() Check if condition is true [1,2,3].some(x => x > 2) // true [1,2,3].every(x => x > 0) // true ✅ Save this for your next interview! 🔖 Which one do you use the most? Comment below! 👇 #JavaScript #Frontend #ReactJS #WebDevelopment #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Understanding callback functions in JavaScript! 🚀 Callback functions are functions passed as arguments to other functions to be executed later. They are commonly used in event handling, asynchronous actions, and more. ⚡️ Why it matters: Callback functions allow developers to write more flexible and reusable code. They are essential in handling tasks that need to be executed at a specific time. 🔹 Step by step breakdown: 1️⃣ Define the main function that will execute the callback. 2️⃣ Create the callback function to be passed as an argument. 3️⃣ Call the main function and pass the callback as an argument. 👨💻 Code example: ```javascript function mainFunction(callback) { // Do something callback(); } function callbackFunction() { console.log('Callback executed!'); } mainFunction(callbackFunction); ``` 💡 Pro tip: Keep callback functions simple and focused on a specific task for better code readability. ⚠️ Common mistake: Forgetting to invoke the callback within the main function, resulting in the function not executing as intended. ❓ Have you ever used callback functions in your projects? Share your experiences below! 💬 🌐 View my full portfolio and more dev resources at tharindunipun.lk #JavaScript #CallbackFunctions #AsyncProgramming #CodeNewbie #WebDevelopment #LearnToCode #DeveloperTips #FunctionCallbacks #EventHandling #AsynchronousJavaScript
To view or add a comment, sign in
-
-
🚀 Day 3/100 — Closures in JavaScript (Used Everywhere in Production) Continuing my 100 Days of JavaScript & TypeScript challenge. Today I explored one of the most powerful (and often misunderstood) concepts in JavaScript: 👉 Closures ⸻ 📌 What is a Closure? A closure is created when a function remembers variables from its outer scope, even after that outer function has finished executing. In simple terms: A function + its lexical environment = Closure ⸻ 📌 Example function createCounter() { let count = 0; return function () { count++; return count; }; } const counter = createCounter(); console.log(counter()); // 1 console.log(counter()); // 2 Even though createCounter() has finished execution, the inner function still has access to count. That’s a closure in action. ⸻ 🧠 Why This Works Because JavaScript functions capture their surrounding scope at the time they are created. This is called the lexical scope. ⸻ 💡 Real-World Use Cases Closures are everywhere in production systems: • Data privacy (encapsulation without classes) • Creating reusable functions • Maintaining state in async operations • Event handlers • Memoization & caching ⸻ 💡 Engineering Insight Closures are the foundation behind: • React hooks • Middleware patterns • Function factories • Many JavaScript libraries But they can also cause issues: ⚠ Memory leaks if references are not handled properly ⚠ Unexpected values in loops (classic bug) Example issue: for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); } Output: 3 3 3 Fix using let (block scope): for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); } Output: 0 1 2 ⸻ ⏭ Tomorrow: Hoisting in JavaScript (var, let, const — what really happens?) #100DaysOfCode #JavaScript #TypeScript #WebDevelopment #SoftwareEngineering #Closures
To view or add a comment, sign in
-
Just published a new blog on 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗖𝗼𝗻𝘁𝗿𝗼𝗹 𝗙𝗹𝗼𝘄. 🚀 Covered how programs make decisions using if, else, and switch, explained with simple examples. 𝗥𝗲𝗮𝗱 𝗵𝗲𝗿𝗲: https://lnkd.in/gGKjx_vS Chai Aur Code ☕ #JavaScript
To view or add a comment, sign in
-
🚀 JavaScript Concepts Series – Day 6 / 30 📌 Closures in JavaScript 👀 Let’s Revise the Basics 🧐 A closure is when a function remembers variables from its outer scope even after the outer function has finished execution. 🔹 Key Points • Inner function can access outer variables • Data persists even after function execution • Useful for data privacy and state management 🔹 Example function outer() { let count = 0; return function inner() { count++; console.log(count); }; } const counter = outer(); counter(); // 1 counter(); // 2 💡 Key Insight Closure → Function + its lexical scope Remembers → Outer variables after execution Closures are widely used in callbacks, event handlers, and React hooks. More JavaScript concepts coming soon. 🚀 #javascript #js #webdevelopment #frontenddeveloper #coding #programming #developers #softwaredeveloper #learnjavascript #javascriptdeveloper #codinglife #devcommunity #webdev #reactjs #mernstack #codingjourney #codeeveryday #developerlife #100daysofcode #techlearning
To view or add a comment, sign in
-
-
JavaScript fun facts that sound fake but are actually real: - "typeof null" → ""object"" (this is a bug from early JS that was never fixed) --- - "[] + []" → """" (empty string) --- - "[] + {}" → ""[object Object]"" --- - "{} + []" → "0" (yes… seriously) --- - "NaN === NaN" → "false" (the only value not equal to itself) --- - "0.1 + 0.2 !== 0.3" (floating point precision issue) --- - Functions are objects in JavaScript → you can add properties to them --- - JavaScript is single-threaded → but still handles async like a pro using event loop --- - "setTimeout(fn, 0)" does NOT run immediately → it runs after the call stack is empty --- If JavaScript ever feels weird, it’s not you. It’s JavaScript. Still learning, still questioning. #JavaScript #WebDevelopment #FrontendDevelopment #Programming #Developers #CodingJourney #TechFacts #BuildInPublic
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