🚀 Day 36/50 – Understanding Functions in JavaScript Today I explored one of the most important concepts in JavaScript — Functions. 🔹 A function is a reusable block of code designed to perform a specific task. 🔹 Functions help make code modular, reusable, and easy to maintain. 📌 1️⃣ Function Declaration function greet(name) { return "Hello, " + name + "!"; } console.log(greet("Priyanka")); 2️⃣ Function Expression const add = function(a, b) { return a + b; }; console.log(add(5, 3)); 3️⃣ Arrow Function (ES6) const multiply = (a, b) => { return a * b; }; console.log(multiply(4, 2)); ✔ Shorter syntax ✔ Cleaner and more readable 4️⃣ Default Parameters function welcome(name = "Guest") { return "Welcome, " + name; } console.log(welcome()); 💡 Key Learnings: ✅ Functions improve code reusability ✅ Arrow functions make code concise ✅ Parameters and return values make functions dynamic ✅ Clean function design is important for scalable applications #Day36 #50DaysOfCode #JavaScript #WebDevelopment #FrontendDevelopment #CodingJourney #LearningEveryday
Understanding JavaScript Functions
More Relevant Posts
-
Today I explored one of the most confusing but fascinating concepts in JavaScript — The Event Loop. JavaScript is single-threaded, but it still handles asynchronous tasks like API calls, timers, and promises smoothly. The magic behind this is the Event Loop. Here’s the simple flow: 1️⃣ Call Stack – Executes synchronous code 2️⃣ Web APIs – Handles async tasks (setTimeout, fetch, DOM events) 3️⃣ Callback Queue / Microtask Queue – Stores callbacks waiting to execute 4️⃣ Event Loop – Moves tasks to the call stack when it’s empty 💡 Example: console.log("Start"); setTimeout(() => { console.log("Timeout"); }, 0); Promise.resolve().then(() => { console.log("Promise"); }); console.log("End"); 🧠 Output: Start End Promise Timeout Why? Because Promises go to the Microtask Queue which runs before the Callback Queue. ✨ Learning this helped me finally understand how JavaScript manages async behavior without multi-threading. Tomorrow I plan to explore another interesting JavaScript concept! Devendra Dhote Ritik Rajput #javascript #webdevelopment #frontenddeveloper #100DaysOfCode #learninginpublic #codingjourney #sheryianscodingschool
To view or add a comment, sign in
-
🚀 Day 86 of My #100DaysOfCode Challenge Today I discovered a lesser-known feature in JavaScript — Symbols. Most developers work with object keys using strings, but JavaScript also provides another unique type called Symbol. A Symbol creates a unique and hidden property key that cannot accidentally conflict with other keys. Example const id = Symbol("id"); const user = { name: "Tejal", [id]: 12345 }; console.log(user.name); // Tejal console.log(user[id]); // 12345 Why Symbols are interesting • Every Symbol is unique • Helps create hidden object properties • Prevents accidental property overwriting • Often used internally in libraries and frameworks Even if two symbols have the same description, they are still different. const a = Symbol("key"); const b = Symbol("key"); console.log(a === b); // false Learning about features like Symbols helps me understand how JavaScript works behind the scenes and how large applications manage object data safely. Exploring deeper concepts every day. 💻✨ #Day86 #100DaysOfCode #JavaScript #WebDevelopment #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 85 of My #100DaysOfCode Challenge One of the most confusing things in JavaScript is the "this" keyword. Many developers think "this" always refers to the current object… but that’s not always true. In JavaScript, the value of "this" depends on how a function is called, not where it is written. Let’s see a quick example 👇 const user = { name: "Tejal", greet() { console.log(this.name); } }; user.greet(); ✅ Output Tejal Here "this" refers to the object that called the function. But look at this 👇 const user = { name: "Tejal", greet: () => { console.log(this.name); } }; user.greet(); ❌ Output undefined Why? Because arrow functions don’t create their own "this". They inherit "this" from the surrounding scope. ⚡ Simple rule to remember • Regular functions → "this" depends on how the function is called • Arrow functions → "this" comes from the outer scope Understanding this small concept can save hours of debugging in real projects. JavaScript keeps reminding me that small details often make the biggest difference. #Day85 #100DaysOfCode #JavaScript #CodingJourney #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Arrays are NOT real arrays in JavaScript. That was one of the most interesting things I learned today while studying Arrays in JavaScript. At first, arrays seem simple — just a collection of elements. But under the hood, JavaScript arrays are actually objects with special behavior, not fixed-size contiguous memory structures like in languages such as C++. What I learned about Arrays: • Arrays in JavaScript are mutable • They can store multiple data types • They are dynamic in size Key operations I practiced: • Adding/removing elements → push(), pop(), shift(), unshift() • Looping → classic for loop and modern iteration methods • Searching → indexOf(), lastIndexOf(), includes() • Manipulation → slice(), splice() • Conversion → join() (array → string) • Spread operator → modern and powerful way to copy/merge arrays One important insight: The sort() method can behave unexpectedly with numbers because it sorts values as strings by default. Example: [10, 2, 5].sort() // Output -> [10, 2, 5] To sort numbers correctly, we need a comparison function. To summarize everything, I created a detailed carousel Notes (Notes given by Rohit Negi). Course Instructor: Rohit Negi | Youtube Channel: Coder Army #JavaScript #WebDevelopment #LearningJourney #BuildInPublic #FrontendDevelopment #Fullstackdevelopment #Coding
To view or add a comment, sign in
-
🚀 Day 39/50 – Scope in JavaScript Today I learned about Scope in JavaScript, which defines where variables can be accessed in a program. 🔹 Scope determines the visibility and accessibility of variables. 📌 Types of Scope in JavaScript 1️⃣ Global Scope – Variables declared outside any function can be accessed anywhere. let name = "Priyanka"; function show() { console.log(name); } show(); 2️⃣ Function Scope – Variables declared inside a function are accessible only within that function. function test() { let msg = "Hello"; console.log(msg); } test(); 3️⃣ Block Scope – Variables declared with let and const inside {} are block-scoped. if(true){ let x = 10; console.log(x); } 4️⃣ Local Scope – Variables declared inside a block or function are local to that area. 💡 Key Learnings: ✅ var → function scoped ✅ let and const → block scoped ✅ Scope helps avoid variable conflicts ✅ Improves code security and readability Thanks for mentors 10000 Coders Raviteja T Abdul Rahman #Day39 #50DaysOfCode #JavaScript #WebDevelopment #FrontendDeveloper #CodingJourney #LearningEveryday
To view or add a comment, sign in
-
-
Most people think they understand JavaScript classes. They don’t. Because JavaScript doesn’t even have real classes. What it actually has is prototypes — and classes are just syntactic sugar on top of them. Today in my T9 class, this completely changed how I look at JS: → Prototype-based inheritance (the actual mechanism) → Traditional vs Modern prototype handling → Constructor Functions (how things worked before classes) Then we moved to what most people are comfortable with: → Classes in JavaScript → constructor, extends, super, static → The 4 pillars of OOP: Encapsulation Inheritance Polymorphism Abstraction But here’s the uncomfortable truth: If you don’t understand prototypes, you don’t actually understand inheritance in JavaScript. You’re just memorizing syntax. That’s why debugging feels random. That’s why “this” behaves weird. That’s why things break in unexpected ways. Now it makes sense. Still early in the journey — but this was one of those “everything clicks” moments. Do you think JS should have stayed purely prototype-based, or are classes a good abstraction? #JavaScript #OOPS #WebDevelopment #LearningInPublic Thankyou Chai Aur Code Suraj Kumar Jha Sir Hitesh Choudhary Sir Piyush Garg Sir
To view or add a comment, sign in
-
-
Day 4 of 30 Days of JavaScript💻....#JavaScript30 Today’s focus was on working with some of the most powerful and commonly used JavaScript array methods: 1 . filter() Used to extract specific data from arrays based on conditions. 2 . map() Learned how to transform array data into a new format. 3 . sort() Sorted complex datasets like objects and strings alphabetically and numerically. 4 . reduce() Takes an array and reduces it into one final result. Through these exercises, I understood how JavaScript can process datasets efficiently using clean and readable functional-style code. Working through these concepts step by step is helping me strengthen my logic and gain more confidence in writing JavaScript, which will definitely support me in frontend development and problem solving. #JavaScript #WebDevelopment #LearningInPublic #CodingJourney #FrontendDevelopment #30DaysOfCode
To view or add a comment, sign in
-
-
Frontend Learning – JavaScript 🧠🧠 This week, I’m transitioning from structure and styling into behavior. I’ve started learning JavaScript, focusing on: • Variables and data types • Functions • Control structures (conditions and loops) What I’m realizing: HTML gives structure. CSS gives style. JavaScript gives life. It’s interesting to see how small scripts can completely change how a page behaves. Frontend is starting to feel more interactive and dynamic. #FrontendDevelopment #JavaScript #LearningJourney #LearningInPublic #WebDevelopment
To view or add a comment, sign in
-
-
🚨 If You’re Struggling With JavaScript, This One Post Might Change Everything I’ve spent 9 years coding and the three concepts that once felt like a maze are now my secret sauce. Let’s break them down in 30 seconds each, no jargon. 1. Async/await. ☕ Think of a coffee order. You place the order and then wait for the barista to finish. While you wait, you can do other things. Async lets the code pause without freezing the whole page, and await makes the pause feel natural. 2. Closures. 🗝️ Imagine a secret drawer inside a box. The drawer keeps its own lock and remembers who opened it. A closure keeps a function’s variables alive even after the outer function finishes. It’s how you create private data in JavaScript. 3. Hoisting. 📚 Picture a librarian who always keeps the books in a stack. When you call a function before you write it, the librarian already knows where it is. Hoisting moves function declarations to the top of the scope so the code can run before the line appears. Habib Ahmed’s recent post on mastering JavaScript in three phases confirms that understanding these ideas early can cut debugging time by 40 percent. Check if your scripts are using async, closures, and hoisting correctly and watch your site feel lighter. ✅ #WebDevelopment #LearnToCode #WordPress #CodingTips #TechEducation #WebDesign #JavaScript #Frontend #React #WebDev #DeveloperLife #CodingLife #WebDesignTips #TechTips #Programming
To view or add a comment, sign in
-
🚀 **Scope in JavaScript (Every Developer Must Understand This)** Scope determines **where a variable is accessible** in your code. If you don’t understand scope, you’ll eventually face unexpected bugs. Let’s break it down 👇 --- ## 🌍 1️⃣ Global Scope Variables declared outside any function are accessible everywhere. ```js let name = "Abhishek"; function greet() { console.log(name); } ``` ✔ Accessible inside functions ✔ Accessible across the file --- ## 🧠 2️⃣ Function Scope (`var`) `var` is function-scoped. ```js function test() { var message = "Hello"; } console.log(message); // ❌ Error ``` It exists only inside the function. --- ## 📦 3️⃣ Block Scope (`let` / `const`) `let` and `const` are block-scoped. ```js if (true) { let age = 25; } console.log(age); // ❌ Error ``` Accessible only inside `{ }` --- ## ⚠ Common Mistake with `var` ```js if (true) { var age = 25; } console.log(age); // 25 😱 ``` Why? Because `var` ignores block scope and leaks outside the block. --- ## 🎯 Best Practice ✅ Use `const` by default ✅ Use `let` when value needs to change ❌ Avoid `var` in modern JavaScript --- Mastering scope makes you stronger in: ✔ Closures ✔ Event Loop ✔ Asynchronous JavaScript ✔ Interviews --- 💬 What should I explain next? 1️⃣ Closures 2️⃣ Event Loop #JavaScript #FrontendDevelopment #WebDevelopment #Programming #CodingInterview #JSConcepts #SoftwareEngineering #FullStackDeveloper #LearnToCode #DeveloperTips #100DaysOfCode #TechCommunity
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