⚙ Understanding Functions in JavaScript — The Building Blocks of Code A function in JavaScript is like a mini-program inside your main program. It allows you to reuse code, organize logic, and make your code modular. --- 💡 Definition: A function is a block of code designed to perform a particular task. You can define it once and call it multiple times. --- 🧠 Syntax: function greet(name) { console.log("Hello, " + name + "! 👋"); } greet("Kishore"); greet("Santhiya"); ✅ Output: Hello, Kishore! 👋 Hello, Santhiya! 👋 --- 🧩 Types of Functions: 1. Named Function function add(a, b) { return a + b; } 2. Anonymous Function const multiply = function(a, b) { return a * b; }; 3. Arrow Function const divide = (a, b) => a / b; --- ⚙ Why Functions Matter: ✅ Reusability ✅ Readability ✅ Easier debugging ✅ Cleaner, modular code --- 🔖 #JavaScript #WebDevelopment #FunctionsInJS #Frontend #CodingTips #JSConcepts #LearnToCode #100DaysOfCode #KishoreLearnsJS #DeveloperJourney #WebDevCommunity #CodeLearning
Understanding JavaScript Functions: The Building Blocks of Code
More Relevant Posts
-
Understanding this in JavaScript this — one of the most misunderstood keywords in JavaScript. It’s simple in theory… until it suddenly isn’t 😅 Here’s what makes it tricky — this depends entirely on how a function is called, not where it’s written. Its value changes with context. Let’s look at a few examples 👇 const user = { name: "Sakura", greet() { console.log(`Hello, I am ${this.name}`); }, }; user.greet(); // "Sakura" ✅ const callGreet = user.greet; callGreet(); // undefined ❌ (context lost) const boundGreet = user.greet.bind(user); boundGreet(); // "Sakura" ✅ (context fixed) Key takeaways 🧠 ✅ this refers to the object that calls the function. ✅ Lose the calling object → lose the context. ✅ Use .bind(), .call(), or .apply() to control it. ✅ Arrow functions don’t have their own this — they inherit from the parent scope. These small details often trip up developers in interviews and real-world debugging sessions. Once you understand the context flow, this becomes a lot less scary to work with. 💪 🎥 I simplified this in my Day 28/50 JS short video— check it out here 👇 👉 https://lnkd.in/gyUnzuZA #javascript #webdevelopment #frontend #backend #programming #learnjavascript #softwaredevelopment #developerslife #techsharingan #50daysofjavascript
To view or add a comment, sign in
-
🚀 Day 30/50 – Function Currying in JavaScript Think of Function Currying like building a relationship. You don’t propose directly 😅 First comes the “Hi Hello 👋” phase → then friendship ☕ → and finally… the proposal ❤️ In JavaScript, instead of passing all arguments at once, Function Currying lets us pass them step by step, each step returning a new function until the final output is achieved. Here’s a simple code analogy from my video: function proposeTo(crush) { return function (timeSpent) { return function (gift) { return `Dear ${crush}, after ${timeSpent} of friendship, you accepted my ${gift}! 🥰`; }; }; } console.log(proposeTo("Sizuka")("3 months")("red rose 🌹")); Each function takes one argument and returns another function — making the code modular, flexible, and easy to reuse. 👉 This is Function Currying — one argument, one step, one perfect result. 🎥 Watch the full short video here: 🔗 https://lnkd.in/g-NkeYBc --- 💡 Takeaway: Function Currying isn’t just a JavaScript trick — it’s a powerful pattern for cleaner, more composable functions that enhance reusability and maintainability in modern frontend code. --- Would love to know: 👉 What’s your favorite JavaScript concept that clicked instantly when you saw it explained simply? #javascript #frontenddevelopment #webdevelopment #coding #programming #softwareengineering #learnjavascript #100daysofjavascript #techsharingan #developers #careergrowth
To view or add a comment, sign in
-
🤖 Day 2 of my 7-Day JavaScript Revision Challenge! Today's focus: Control Flow & Functions in JavaScript Control flow defines how your JavaScript program runs — step-by-step or through decisions, loops, and functions. Understanding it helps you write logic-driven, structured, and reusable programs. ⚙️ ⚡ 1. Conditional Statements 🔹 Use if, else if, and else to make decisions in your program. 🔹 switch statements help handle multiple conditions more cleanly. 🔹 Conditions guide your program to perform different actions based on logic. 🔁 2. Loops 🔹 Loops allow you to repeat tasks until a specific condition is met. 🔹 Common types include for, while, and do...while. 🔹 Be mindful of infinite loops by updating conditions correctly. ⚙️ 3. Functions 🔹 Functions group reusable pieces of code, keeping your program modular and organized. 🔹 They can take inputs (parameters) and return outputs (results). 🔹 Arrow functions provide a shorter syntax for writing functions. 💡 4. Practice Challenges ✅ Write a function to find the maximum of two numbers. ✅ Use a loop to print all even numbers between 1 and 20. ✅ Build a simple calculator using switch. 🔥 Key Takeaway: Mastering control flow and functions builds the foundation for writing clean, efficient, and reusable JavaScript code. 🚀 Up next — Day 3: Arrays & Objects! #JavaScript #7DaysOfCode #WebDevelopment #CodingJourney #LearnJavaScript #FrontendDevelopment #JSChallenge #CodeNewbie #DeveloperCommunity #Programming #TechLearning #DailyCoding #JSPractice #FunctionsInJS #ControlFlow #AmanCodes
To view or add a comment, sign in
-
-
How JS Converts [] + {} to [object Object] —🤯 JavaScript can be weirdly magical sometimes. Ever tried this in your console? 👇 [] + {} // Output: "[object Object]" At first glance, it looks confusing — why does an empty array and an empty object become a string? Let’s decode the magic 🪄 1️⃣ + Operator in JS The + operator doesn’t just add numbers — it can also concatenate strings. 2️⃣ Type Conversion Happens! [] (empty array) → when converted to string becomes "" (empty string). {} (empty object) → when converted to string becomes "[object Object]". 3️⃣ Final Expression So JS actually does: "" + "[object Object]" → "[object Object]" ✅ Bonus twist: Try reversing it: {} + [] Now it gives 0 because {} is treated as an empty block,not an object. 🤯 JavaScript — where logic meets magic ✨ 🔹 Follow Prashansa Sinha for more fun JS mysteries and simple explanations 👩💻 #JavaScript #WebDevelopment #Coding #Frontend #JS #LearnToCode #Programming #TechCommunity #Developers #CodeNewbie #WebDev
To view or add a comment, sign in
-
💡 Understanding var, let, and const in JavaScript — A Must for Every Developer! When writing JavaScript, knowing how variables behave is crucial for clean and bug-free code. Here’s a quick breakdown 👇 🔹 var Scope: Function-scoped Hoisted: Yes (initialized as undefined) Re-declaration: Allowed ⚠️ Can cause unexpected results due to hoisting and re-declaration. 🔹 let Scope: Block-scoped ({ }) Hoisted: Yes (but not initialized — Temporal Dead Zone) Re-declaration: ❌ Not allowed in same scope ✅ Preferred for variables that can change. 🔹 const Scope: Block-scoped Hoisted: Yes (not initialized — Temporal Dead Zone) Re-declaration / Re-assignment: ❌ Not allowed ✅ Use for constants and values that never change. 🔍 Example: { var a = 10; let b = 20; const c = 30; } console.log(a); // ✅ Works (function-scoped) console.log(b); // ❌ Error (block-scoped) console.log(c); // ❌ Error (block-scoped) 🧠 Pro tip: Always prefer let and const over var for predictable and safer code. ✨ Which one do you use most often — let or const? Let’s discuss 👇 #JavaScript #WebDevelopment #Frontend #CodingTips #ES6
To view or add a comment, sign in
-
Variable Declarations @ JavaScript Simplified👨💻 In JavaScript, we have three keywords to declare variables: var, let, and const. 💢Each behaves differently when it comes to redeclaration and reassignment 👇 🔸 var ✅ Redeclaration: Allowed ✅ Reassignment: Allowed 🧩 Example: var x = 10; var x = 20; // works fine ⚠️ Best avoided — can cause accidental overwriting of variables. 🔸 let ❌ Redeclaration: Not allowed ✅ Reassignment: Allowed 🧩 Example: let y = 30; y = 40; // valid let y = 50; // ❌ SyntaxError 👍 Use let when the value of a variable might change later. 🔸 const ❌ Redeclaration: Not allowed ❌ Reassignment: Not allowed 🧩 Example: const z = 50; z = 60; // ❌ TypeError 🔒 Use const for values that should never change. 👉 Quick recap: 🔹Use let when updates are needed. 🔹Use const when the value stays fixed. 🔹Avoid var to keep your code predictable and clean. #JavaScript #WebDevelopment #CodingTips #LearningJS #FrontendDevelopment
To view or add a comment, sign in
-
*5 Things I Wish I Knew When Starting JavaScript 👨💻* Looking back, JavaScript was both exciting and confusing when I started. Here are 5 things I wish someone had told me earlier: *1. `var` is dangerous. Use `let` and `const`* – `var` is function-scoped and can lead to unexpected bugs. `let` and `const` are block-scoped and safer. *2. JavaScript is asynchronous* – Things like `setTimeout()` and `fetch()` don’t behave in a straight top-down flow. Understanding the *event loop* helps a lot. *3. Functions are first-class citizens* – You can pass functions as arguments, return them, and even store them in variables. It’s powerful once you get used to it. *4. The DOM is slow – avoid unnecessary access* – Repeated DOM queries and manipulations can hurt performance. Use `documentFragment` or batch changes when possible. *5. Don’t ignore array methods* – `map()`, `filter()`, `reduce()`, `find()`… they make code cleaner and more readable. I wish I started using them sooner. 💡 *Bonus Tip:* `console.log()` is your best friend during debugging! If you’re starting out with JS, save this. And if you're ahead in the journey — what do *you* wish you knew earlier? #JavaScript #WebDevelopment #CodingJourney #Frontend #LearnToCode #DeveloperTips
To view or add a comment, sign in
-
Relearning Frontend Fundamentals: A technical look at nodes in DOM tree can you guess how many nodes are there in the following html ? <body> <h1>DOM</h1> text1 <p>Document Object Model</p> white text2 </body> The answer is 9! ,Because all line breaks (\n) and indentations ( ) are parsed as separate Text Nodes (nodeType: 3). These fill the gaps between your Element Nodes. Even comments are treated as node (nodeType: 8) The most important node types are element (tags) and text (content) You can see the properties of each node below which shows relational data of each node with other nodes , value , type of node For more details about node properties ,types and methods have a look at mdn docs : https://lnkd.in/dqCP-yVC #FrontendDevelopment #JavaScript #DOM #WebDev #BrowserInternals
To view or add a comment, sign in
-
-
*5 Things I Wish I Knew When Starting JavaScript 👨💻* Looking back, JavaScript was both exciting and confusing when I started. Here are 5 things I wish someone had told me earlier: *1. var is dangerous. Use "let" and "const" "var" is function-scoped and can lead to unexpected bugs. "let" and "const" are block-scoped and safer. *2. JavaScript is asynchronous Things like "setTimeout()"and "fetch()" don’t behave in a straight top-down flow. Understanding the *event loop* helps a lot. *3. Functions are first-class citizens* – You can pass functions as arguments, return them, and even store them in variables. It’s powerful once you get used to it. *4. The DOM is slow – avoid unnecessary access* – Repeated DOM queries and manipulations can hurt performance. Use "documentFragment" or batch changes when possible. *5. Don’t ignore array methods* map(), "filter()" , "reduce()", "find()"… they make code cleaner and more readable. I wish I started using them sooner. 💡 *Bonus Tip:* "console.log()" is your best friend during debugging! If you’re starting out with JS, save this. And if you're ahead in the journey — what do *you* wish you knew earlier? #JavaScript #WebDevelopment #CodingJourney #Frontend #LearnToCode #DeveloperTips
To view or add a comment, sign in
-
Today I explored how JavaScript executes inside the browser, and it was truly fascinating to understand the step-by-step process behind the scenes! 💡 Here’s what I learned 👇 🔹 The browser starts by loading the HTML and identifying any <script> tags. 🔹 Once found, the code is sent to the JavaScript Engine (like Chrome’s V8). 🔹 The engine performs three key steps — ✨ Parsing: Reads and converts code into an Abstract Syntax Tree (AST). ⚙️ Compilation (JIT): Translates JS into optimized machine code for faster execution. 🧩 Execution: Runs the code in the Call Stack, while variables and objects are managed in the Memory Heap. 🔹 For asynchronous operations (set Timeout, fetch, etc.), the Web APIs, Callback Queue, and Event Loop coordinate to ensure non-blocking execution. 💬 In short: HTML Parsing → JS Engine → Call Stack → Web APIs → Callback Queue → Event Loop → Execution Understanding this flow helps in writing efficient, optimized, and clean JavaScript code. Excited to continue learning and sharing my progress each day under the guidance of Sudheer Velpula Sir. 🙌 #JavaScript #WebDevelopment #Frontend #LearningJourney #Coding #SudheerSir
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