Day 7/100 of JavaScript 🚀 Today’s Topic: Taking input in JavaScript. In browser-based JavaScript, input can be taken using: - "prompt()" - Input fields (DOM) On platforms like LeetCode, input is already provided as function parameters Example: var twoSum = function(nums, target) { // input is already given }; So the focus is on writing logic, not handling input However, some coding platforms (or local environments) do not provide inbuilt input handling. In such cases, we use Node.js Example: process.stdin.on("data", (data) => { const input = data.toString().trim(); console.log(input); }); This allows us to read input from the console Key understanding: - Platforms like LeetCode handle input internally - Other platforms and local setups require manual input handling using Node.js Understanding both approaches is important for coding practice #Day7 #JavaScript #100DaysOfCode
JavaScript Input Handling: LeetCode vs Node.js
More Relevant Posts
-
Day 4/100 of JavaScript 🚀 Today’s focus: Functions in JavaScript Functions are reusable blocks of code used to perform specific tasks Some important types with example code: 1. Parameterized function → takes input function greet(name) { return "Hello " + name; } greet("Apsar"); 2. Pure function → same input always gives same output, no side effects function add(a, b) { return a + b; } add(2, 3); 3. Callback function → function passed into another function function processUser(name, callback) { callback(name); } processUser("Apsar", function(name) { console.log("User:", name); }); 4.Function expression → function stored in a variable const multiply = function(a, b) { return a * b; }; 5.Arrow function → shorter syntax const square = (n) => n * n; Key understanding: Functions are first-class citizens in JavaScript — they can be passed, returned, and stored like values #Day4 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
Day 22/100 of JavaScript Today’s topic: Prototypes in JavaScript JavaScript uses a prototype-based inheritance model. Every object in JavaScript has an internal link to another object called its prototype. Example function Person(name) { this.name = name; } Person.prototype.greet = function () { console.log("Hello " + this.name); }; const user = new Person("Apsar"); user.greet(); Here, "greet" is not inside the object itself, but shared through the prototype. 🔹Prototype chain If a property or method is not found on the object, JavaScript looks up the prototype chain. console.log(user.toString()); 👉 "toString()" comes from the base object prototype. 🔑 Key points - Functions have a "prototype" property. - Objects inherit from their prototype. - Helps in memory efficiency by sharing methods. #Day22 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 2/108 – Variables in JavaScript (var, let, const) Continuing my 108-day JavaScript journey — today I learned about variables 👇 👉 What are Variables? Variables are containers used to store data values in a program. In JavaScript, we mainly use 3 types: var, let, and const 🔹 var • Old way of declaring variables • Function scoped • Can be re-declared and updated 🔹 let • Block scoped • Can be updated but not re-declared in the same scope 🔹 const • Block scoped • Cannot be updated or re-declared • Must be initialized when declared 💻 Example: var name = "John"; let age = 22; const country = "India"; age = 23; // allowed // country = "USA"; ❌ not allowed 🧠 Key Insight: Always prefer let and const over var in modern JavaScript. 🔥 Learning step by step — consistency is the key! Are you using var, let, or const in your projects? 👇 #JavaScript #WebDevelopment #CodingJourney #LearningInPublic #108DaysOfCode
To view or add a comment, sign in
-
-
🚀 Why Does null Show as an Object in JavaScript? 🤯 While practicing JavaScript, I came across something interesting: let myVar = null; console.log(typeof myVar); // Output: object At first, it feels confusing… why is null an object? 🤔 💡 Here’s the simple explanation: null is actually a primitive value that represents "no value" or "empty". But when JavaScript was first created, there was a bug in the typeof operator. Due to this bug, typeof null returns "object" instead of "null". ⚠️ This behavior has been kept for backward compatibility, so changing it now would break existing code. 🔍 Key Takeaways: null → means "nothing" (intentional empty value) typeof null → returns "object" (this is a historical bug) Objects (like {}) also return "object" 💻 Example: let myObj = { name: "John" }; console.log(typeof null); // object ❌ (bug) console.log(typeof myObj); // object ✅ (correct) 📌 Conclusion: Even though both return "object", they are completely different in meaning. 👉 JavaScript is powerful, but it has some quirky behaviors—this is one of them! #JavaScript #WebDevelopment #CodingJourney #100DaysOfCode #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 Understanding Recursion + Finding Maximum in Nested Arrays (JavaScript) Today I practiced a powerful concept in JavaScript — recursion with nested arrays — and used it to solve a real problem: 👉 Find the maximum number from a deeply nested array 💡 Example: [1, 0, 7, [2, 5, [10], 4]] 🔍 Approach I followed: ✅ Step 1: Used recursion to flatten the nested array If the element is a number → push into result If it’s an array → call the same function again ✅ Step 2: After flattening, used a loop to find the maximum value 🧠 Key Learnings: • Each recursive call creates its own memory (execution context) • Data is temporarily stored in the call stack • The return keyword helps pass results back step by step • Without capturing the returned value, recursion results can be lost • Breaking problems into smaller parts makes complex logic easier ⚡ Final Output: 👉 Maximum number: 10 💬 This exercise really helped me understand: How recursion works internally How data flows through function calls Difference between primitive and reference types #JavaScript #Recursion #ProblemSolving #WebDevelopment #CodingJourney
To view or add a comment, sign in
-
Day 2/100 of JavaScript 🚀 Today’s Topic: "let", "const", "var", hoisting and TDZ. "var", "let", and "const" are used to declare variables, but they differ in scope and initialization behavior - "var" is function-scoped and during the creation phase it gets initialized with "undefined", so it can be accessed before assignment. - "let" and "const" are block-scoped and are registered in memory during creation, but not initialized immediately. This leads to TDZ (Temporal Dead Zone) a phase where the variable exists in memory but remains uninitialized and cannot be accessed. Accessing "let" or "const" variables before initialization results in a ReferenceError. - "const" must be initialized at declaration and cannot be reassigned. - "let" allows reassignment but not redeclaration in the same scope. These differences make "let" and "const" more predictable and safer compared to "var". #Day2 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 979 of #1000DaysOfCode ✨ 4 Useful Number Functions in JavaScript (With Cool Examples) JavaScript provides many built-in number utilities — but most developers only use a few of them. In today’s post, I’ve shared 4 super useful number functions in JavaScript along with some cool and practical examples for each. These functions can help you handle number validation, formatting, and edge cases more effectively in real-world applications. Small utilities like these might look simple, but they can save you time and help you write cleaner and more reliable logic. Once you start using them properly, you’ll notice how often they come in handy while working with data. If you work with numbers, calculations, or user inputs in JavaScript, these functions are definitely worth knowing. 👇 Which JavaScript number function do you use the most in your projects? #Day979 #learningoftheday #1000daysofcodingchallenge #FrontendDevelopment #WebDevelopment #JavaScript #React #CodingCommunity #JSDevelopers
To view or add a comment, sign in
-
🚀 Day 10 of My JavaScript Journey ✨Today I explored how JavaScript actually works behind the scenes — and honestly, it changed the way I look at code completely 🤯 Here’s what I learned 👇 🧠 How JavaScript Code RunsJavaScript doesn’t just execute line by line — it first creates an Execution Context which manages everything. ⚙️ Execution Context Phases1️⃣ Memory Allocation Phase Variables get stored with undefined Functions are stored completely 2️⃣ Execution Phase Code runs line by line Values get assigned and functions execute 📦 Call Stack & Execution Flow JavaScript uses a Call Stack to manage function calls Each function creates its own execution context Stack follows LIFO (Last In, First Out) 💾 Stack vs Heap Memory Stack → Stores primitive values (fast ⚡) Heap → Stores objects (reference-based 🧩) 🤖 Interpreter BehaviorJavaScript reads and executes code step by step using an interpreter — not compiled like some other languages. ❓ Why undefined Appears?Because during memory phase, variables are declared but not initialized yet. ⬆️ Hoisting Explained var is hoisted with undefined Functions are fully hoisted let & const are hoisted but stay in Temporal Dead Zone (TDZ) ❌ 🚫 Temporal Dead Zone (TDZ)You can’t access let & const variables before initialization — it throws an error. ⚠️ Function Expressions vs Hoisting Function declarations → hoisted ✅ Function expressions → behave like variables ❌ 💡 Key TakeawayUnderstanding execution context, memory, and hoisting makes debugging WAY easier and helps write cleaner code 🔥 📌 Slowly moving from writing code → to understanding how it actually works inside #JavaScript #WebDevelopment #MERNStack #CodingJourney #LearnToCode #FrontendDevelopment #DeveloperLife
To view or add a comment, sign in
-
-
Today I was revisiting Higher Order Functions in JavaScript, and it completely changed how I look at reusable logic. At a basic level, I used to think: 👉 A higher order function is just a function that takes another function as an argument or returns a function. But the real power is much deeper. While working with map, filter, and similar methods, I realized something important: Instead of repeating the same logic across multiple components, we can extract the core logic into a single reusable higher order function. 🔥 What this changes: No repeated iteration logic in every component Centralized business logic Easy updates — change once, impact everywhere Cleaner, more maintainable codebase if requirements change, we don’t need to update multiple components anymore. We just update the core function — and everything adapts automatically. That’s the real strength of JavaScript functional programming. It made me realize how powerful and elegant JavaScript can be when we use it properly. Next, I’m planning to go deeper into more core JavaScript concepts and explore how they improve real-world code design. #javascript #reactjs #typescript
To view or add a comment, sign in
-
-
Useful JavaScript Tricks Developers Should Know 🚀 JavaScript has some powerful features that can make your code cleaner and more efficient. Here are a few JavaScript tricks I use regularly: 🔹 Destructuring Extract values from objects easily const { name, age } = user; 🔹 Optional Chaining Avoid undefined errors user?.profile?.name 🔹 Default Parameters Set default values function greet(name = "Developer") { return `Hello ${name}`; } 🔹 Spread Operator Copy arrays or objects const newArray = [...oldArray]; 🔹 Short Circuit Evaluation Cleaner conditional logic isLoggedIn && showDashboard() These small tricks can make your code more readable and efficient. Still learning JavaScript every day 🚀 What’s your favorite JavaScript trick? #JavaScript #FrontendDeveloper #ReactNative #SoftwareEngineer #CodingTips #WebDevelopment
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