🎯 Function Parameters & Arguments in JavaScript — Pass Data Like a Pro! Functions become powerful when you can send data to them — that’s where parameters and arguments come in! Let’s break it down 👇 --- 💡 Definition: Parameters are variables listed in the function definition. Arguments are the actual values you pass when calling the function. --- 🧩 Example: function greet(name) { // 'name' is a parameter console.log("Hello, " + name + "! 👋"); } greet("Kishore"); // 'Kishore' is an argument greet("Santhiya"); ✅ Output: Hello, Kishore! 👋 Hello, Santhiya! 👋 --- ⚙ Multiple Parameters Example: function add(a, b) { console.log("Sum:", a + b); } add(5, 10); add(3, 7); ✅ Output: Sum: 15 Sum: 10 --- 🧠 Key Points: Parameters are placeholders. Arguments are real data. You can pass default values too: function greet(name = "Guest") { console.log("Welcome, " + name); } greet(); // Output: Welcome, Guest --- 🔖 #JavaScript #Functions #WebDevelopment #Frontend #JSConcepts #CodingTips #LearnToCode #WebDevCommunity #100DaysOfCode #DeveloperJourney #ProgrammingBasics
Understanding Parameters and Arguments in JavaScript
More Relevant Posts
-
🧠 JavaScript Closures — Explained in a Simple Way In JavaScript, a closure happens when a function remembers and can still use variables from the place where it was created — even after the outer function has finished. Think of it like having a key to a room. Even if the door is closed later… you can still enter and use the items inside. 🔑🚪 Here’s a quick example: function outer() { let message = "Hello 👋"; return function inner() { console.log(message); }; } const fn = outer(); fn(); // 👉 Output: Hello 👋 ✅ inner() still has access to message ✅ That memory power = Closure 🌟 Why Closures Are Useful? Private data (hidden variables) Remembering values (callbacks, timers) Custom functions (pre-filled data) Example: function greet(name) { return () => console.log("Hello " + name); } const hiJohn = greet("John"); hiJohn(); // Hello John 🔹One-line Definition: Closure = Function + Remembered outer variables If you found this helpful, follow for more: JavaScript | Full Stack | Real-world Coding Tips #JavaScript #Closures #Coding #WebDevelopment #LearnJS #Cognothink
To view or add a comment, sign in
-
💛 𝗗𝗮𝘆 𝟯 — 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁: 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀 𝗮𝗻𝗱 𝗖𝗹𝗼𝘀𝘂𝗿𝗲𝘀 Today’s focus was one of the most powerful and favorite topics in JavaScript — 𝗖𝗹𝗼𝘀𝘂𝗿𝗲𝘀 🔁 💡 𝗖𝗼𝗻𝗰𝗲𝗽𝘁: A closure gives a function access to its outer scope even after the outer function has finished execution. This enables data encapsulation, function factories, and state preservation. 💻 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 𝟭 — 𝗕𝗮𝘀𝗶𝗰 𝗖𝗹𝗼𝘀𝘂𝗿𝗲: function outer() { let count = 0; return function inner() { count++; console.log("Count:", count); }; } const counter = outer(); counter(); // Count: 1 counter(); // Count: 2 🧠 Here, inner() remembers the variable count from outer() even after it’s done — that’s closure in action! 💻 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 𝟮 — 𝗣𝗿𝗮𝗰𝘁𝗶𝗰𝗮𝗹 𝗨𝘀𝗲: Closures power concepts like private variables: function createUser(name) { return { getName: function () { return name; }, }; } const user = createUser("Ravi"); console.log(user.getName()); // Ravi 🧠 𝗞𝗲𝘆 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴𝘀: ✅ Inner functions retain references to outer scope variables. ✅ Closures are the backbone of callbacks, event handlers, and functional programming. ✅ Used in frameworks like React (hooks rely on closure principles). 🔥 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Closures aren’t magic — they’re just functions remembering where they came from. #JavaScript #Closures #Functions #FrontendDevelopment #100DaysOfCode #LearningEveryday
To view or add a comment, sign in
-
🔓 JS Tip: Stop Manually Assigning Object Properties! 🔓 Tired of writing var name = user.name; var email = user.email;? Destructuring lets you "pull apart" objects and arrays and grab just the pieces you need, all in one line. ❌ The Old Way (One by One) js code - var user = { id: 123, name: 'Alex', email: 'alex@example.com' }; var id = user.id; var name = user.name; var email = user.email; --- ✅ The New Way (Destructuring) js code - const user = { id: 123, name: 'Alex', email: 'alex@example.com' }; // "From 'user', get 'id', 'name', and 'email' // and put them in variables with the same name." const { id, name, email } = user; ---- 🔥 Why it's better: It's incredibly clean and efficient, especially with large objects from an API. You declare what data you want, not the tedious steps to get it. It's also perfect for function arguments and React props. 👉 View My New Services - https://lnkd.in/g5UaKeTc 🎇 Do you want more tips like this? Do follow and write "Yes" in the comment box. #javascriptTips #JavaScript #JSTips #ES6 #Developer #Programming #WebDev #ReactJS #NodeJS #Coding #TechTips #WebDeveloper #MdRedoyKayser #Webxpanda #WordPress
To view or add a comment, sign in
-
-
Today, I explored Strings in JavaScript — one of the most common and powerful data types we use to handle text. Strings are sequences of characters enclosed in quotes (' ', " ", or ` `). Let’s dive into some key concepts 1. Creating Strings let single = 'Hello'; let double = "World"; let template = `Hello, World!`; 🔹 2. String Concatenation Joining multiple strings together: let firstName = "John"; let lastName = "Doe"; let fullName = firstName + " " + lastName; console.log(fullName); // John Doe You can also use template literals for cleaner syntax: let fullName2 = `${firstName} ${lastName}`; console.log(fullName2); // John Doe String Length let text = "JavaScript"; console.log(text.length); // 10 Accessing Characters let word = "Code"; console.log(word[0]); // C console.log(word.charAt(2)); // d Common String Methods let message = " Hello JavaScript! "; console.log(message.toUpperCase()); // " HELLO JAVASCRIPT! " console.log(message.toLowerCase()); // " hello javascript! " console.log(message.trim()); // "Hello JavaScript!" console.log(message.includes("Java")); // true console.log(message.replace("Hello", "Hi")); // " Hi JavaScript! " Splitting and Joining Strings let sentence = "I love JavaScript"; let words = sentence.split(" "); // ["I", "love", "JavaScript"] console.log(words.join("-")); // "I-love-JavaScript" Key takeaway: Strings are everywhere — from user inputs to API responses. Understanding string methods will make your JavaScript code more efficient and expressive. #100DaysOfCode #JavaScript #CodingChallenge #WebDevelopment #LearnInPublic #CodeNewbie
To view or add a comment, sign in
-
🔓 JS Tip: Stop Manually Assigning Object Properties! 🔓 Tired of writing var name = user.name; var email = user.email;? Destructuring lets you "pull apart" objects and arrays and grab just the pieces you need, all in one line. ❌ The Old Way (One by One) js code - var user = { id: 123, name: 'Alex', email: 'alex@example.com' }; var id = user.id; var name = user.name; var email = user.email; --- ✅ The New Way (Destructuring) js code - const user = { id: 123, name: 'Alex', email: 'alex@example.com' }; // "From 'user', get 'id', 'name', and 'email' // and put them in variables with the same name." const { id, name, email } = user; ---- 🔥 Why it's better: It's incredibly clean and efficient, especially with large objects from an API. You declare what data you want, not the tedious steps to get it. It's also perfect for function arguments and React props. 👉 View Our Services - www.webxpanda.com 🎇 Do you want more tips like this? Do follow and write "Yes" in the comment box. #javascriptTips #JavaScript #JSTips #ES6 #Developer #Programming #WebDev #ReactJS #NodeJS #Coding #TechTips #WebDeveloper #MdRedoyKayser #Webxpanda #WordPress
To view or add a comment, sign in
-
-
🔓 JS Tip: Stop Manually Assigning Object Properties! 🔓 Tired of writing var name = user.name; var email = user.email;? Destructuring lets you "pull apart" objects and arrays and grab just the pieces you need, all in one line. ❌ The Old Way (One by One) js code - var user = { id: 123, name: 'Alex', email: 'alex@example.com' }; var id = user.id; var name = user.name; var email = user.email; --- ✅ The New Way (Destructuring) js code - const user = { id: 123, name: 'Alex', email: 'alex@example.com' }; // "From 'user', get 'id', 'name', and 'email' // and put them in variables with the same name." const { id, name, email } = user; ---- 🔥 Why it's better: It's incredibly clean and efficient, especially with large objects from an API. You declare what data you want, not the tedious steps to get it. It's also perfect for function arguments and React props. 👉 View Our Services - www.webxpanda.com 🎇 Do you want more tips like this? Do follow and write "Yes" in the comment box. #javascriptTips #JavaScript #JSTips #ES6 #Developer #Programming #WebDev #ReactJS #NodeJS #Coding #TechTips #WebDeveloper #MdRedoyKayser #Webxpanda #WordPress
To view or add a comment, sign in
-
-
Going back to basics 🌱 Closures and Garbage Collection in JavaScript In the last post, we saw how "Closures" keep variables alive even after their parent function finishes. Now let us understand what happens behind the scenes and why that can sometimes become a problem? When a "function" runs, "JavaScript" creates an "Execution Context" and stores all its variables. After it finishes, those variables are usually removed by the "Garbage Collector" but not when an inner function (closure) still holds a reference to them. That is what makes closures powerful, they help functions remember values even after the outer function is done. But if that memory holds large data that you no longer need, the "Garbage Collector" cannot clean it, and that can lead to "memory leaks". Let us see a simple example - both "bigData" and "leak" are variables. "new Array" creates an empty array of length 1000000 h "bigData" and "leak" are variables. "new Array" creates an empty array of length 1000000 that little big length right...? Since "leak" still references "bigData" through the closure, the array stays in memory even after "outer()" finishes , the garbage collector cannot remove it until the reference is gone, which can lead to a memory leak if not handled properly. #Javascript #Frontend
To view or add a comment, sign in
-
-
🚀 Let’s talk about something every beginner confuses — JavaScript Objects vs JSON Strings 💡 👉 JavaScript Object It’s the real, usable data inside your code. Example: const user = { name: "Anas", age: 21 }; You can access it directly: user.name → gives you "Anas" 👉 JSON String It’s the text version of that object — like saving it in a file or sending it over the internet. Example: const jsonString = '{"name": "Anas", "age": 21}'; Looks similar, but it’s just text — you can’t do jsonString.name because it’s not an object yet! 💡 Real-world use case: When your app talks to a server — say a weather app fetching data — the server sends info as JSON strings. Your JavaScript code then converts it into an object using: const data = JSON.parse(jsonString); …and now you can use it easily! 🧠 Think of it like this: Object → your living data inside JS JSON → a suitcase carrying that data safely to another computer 💼 #JavaScript #WebDevelopment #Beginners #CodingSimplified #JSON #Frontend
To view or add a comment, sign in
-
-
🔥 Day 33 of #100DaysLearningChallenge 🧠 Topic: How to Handle JSON Files in JavaScript (Node.js) 📘 Overview Today, I learned how to read and access data from a JSON file using JavaScript in Node.js. JSON (JavaScript Object Notation) is one of the most common formats for storing and exchanging data — and knowing how to handle it in JS is super useful! 📂 What the JSON File Contains: ✅ Simple values → strings, numbers, booleans ✅ Nested objects → e.g. a client object with multiple properties ✅ Arrays → lists of numbers or strings ✅ Arrays of objects → e.g. a score array containing multiple records ⚙️ How It Works 1️⃣ Loading the JSON File We can use require() in Node.js to import the JSON file. It automatically parses it and returns a JavaScript object. ✔️ typeof data → returns "object" 2️⃣ Iterating Through the Data We loop through each property using for...in. Depending on the type of data, we handle it differently: Simple values (string, number, boolean): print key-value pairs Arrays: If it contains numbers → print each number If it contains objects → use a nested loop to access each property Nested objects: loop through their internal keys and values 💡 Key Concepts Learned 🔹 Type Checking: typeof helps detect if a value is a primitive or object 🔹 Array Detection: instanceof Array distinguishes arrays from objects 🔹 Nested Loops: Used for deep data traversal 🔹 Error Handling: Always good to wrap in try-catch for safety 🧩 Expected Output Example: name - Rohan age - 34 is_active - true id - A101 username - rohan123 30 40 25 60 f1 - 23 f2 - 25 f3 - 27 ... This method allows reading all data — even deeply nested structures — easily! 🙏 Special Thanks to Saurabh Shukla Sir for explaining everything so clearly and practically. 💻 My Code: https://lnkd.in/d4TnHZGj) #100DaysLearningChallenge #JavaScript #NodeJS #JSON #WebDevelopment #Backend #Programming #DataHandling #CodingJourney
To view or add a comment, sign in
-
🚀 Deep Clone an Object in JavaScript (the right way!) Most of us have tried this at least once: const clone = JSON.parse(JSON.stringify(obj)); …and then realized it breaks when the object has functions, Dates, Maps, or undefined values 😬 Let’s fix that 👇 ❌ The Problem with JSON.parse(JSON.stringify()) >It’s quick, but it: >Removes functions >Converts Dates into strings >Skips undefined, Infinity, and NaN >Fails for Map, Set, or circular references ✅ Option 1: Use structuredClone() (Modern & Fast) Available in most modern browsers and Node.js (v17+). It can handle Dates, Maps, Sets, and even circular references — no errors, no data loss. const deepCopy = structuredClone(originalObject); Simple, native, and reliable 💪 ✅ Option 2: Write Your Own Recursive Deep Clone Useful for older environments or if you want to understand the logic behind cloning. 💡 Pro Tip: If you’re working with complex or nested data structures, always prefer structuredClone(). It’s the modern, built-in, and safest way to deep clone objects in JavaScript. 🔥 Found this useful? 👉 Follow me for more JavaScript deep dives made simple — one post at a time. #JavaScript #WebDevelopment #FrontendDevelopment #CodingTips #LearnJavaScript #Programming #DeveloperCommunity #WebDev #ES6 #JSDeveloper #JavaScriptTips #JavaScriptObjects #JavaScriptClone #JavaScriptCloneObject
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