‘F’ in JavaScript stands for fun! 🎉 🪩 Time complexity looks good on paper. But small language details can slow your code a lot. Big O notation says s[j] and s.charCodeAt(j) are both O(1). But in reality, s.charCodeAt(j) returns a small number that the JS engine caches with no need to allocate new memory. Meanwhile, s[j] creates a new String object every time, using up memory and slowing your code. A few milliseconds, but it hurts terribly in performance tests. #interview #javascript #node
Mariusz Najwer’s Post
More Relevant Posts
-
💻 JavaScript Intermediate – Custom map() Function The map() method is widely used to transform arrays. Here’s how you can implement it manually. 📌 Problem: Apply a function to each element of an array and return a new array. function customMap(arr, callback) { let result = []; for (let i = 0; i < arr.length; i++) { result.push(callback(arr[i])); } return result; } let numbers = [1, 2, 3]; let doubled = customMap(numbers, function(num) { return num * 2; }); console.log(doubled); 📤 Output: [2, 4, 6] 📖 Explanation: • map() creates a new array by applying a function to each element. • Here, we manually implemented the same logic using a loop and callback. 💡 Tip: Understanding this helps you grasp how higher-order functions work in JavaScript. #JavaScript #Coding #WebDevelopment #FrontendDevelopment #LearnToCode #ProgrammingTips
To view or add a comment, sign in
-
-
🚀 30 Days of JavaScript Tricky Questions – Day 2 🧠 Topic: Closures in JavaScript function outer() { let outerVar = "I am from outer function!"; function inner() { let innerVar = "I am from inner function!"; console.log(outerVar); console.log(innerVar); } return inner; } const myClosure = outer(); myClosure(); Can you guess what should be logs in the console🤔 💬 Drop your answer in the comments #JavaScript #JSClosures #FrontendDeveloper #WebDevelopment #100DaysOfCode #LearningJavaScript #InterviewPrep
To view or add a comment, sign in
-
😂 **JavaScript Be Like…** “This is my favorite language.” Until… ```js "11" + 1 // "111" "11" - 1 // 10 ``` And suddenly everyone is sweating 😅 --- ## 💡 What’s Happening Here? 🔹 `"11" + 1` → `+` triggers **string concatenation** → Result: `"111"` 🔹 `"11" - 1` → `-` forces **numeric conversion** → Result: `10` --- ### 🚀 Welcome to JavaScript Type Coercion JavaScript automatically converts types depending on the operator. ✔ `+` → Can concatenate strings ✔ `-`, `*`, `/` → Force numeric conversion This flexibility is powerful… But if you don’t understand it, it becomes dangerous. --- ### 🎯 Lesson: Always be aware of data types. Use `Number()`, `String()`, or `parseInt()` explicitly when needed. Because in JavaScript… It works. But not always the way you expect 😄 --- 💬 Have you ever been confused by JS type coercion? #JavaScript #FrontendDevelopment #WebDevelopment #ProgrammingHumor #CodingLife #JSConcepts #SoftwareEngineering #FullStackDeveloper #LearnToCode #TechCommunity #DeveloperMemes #100DaysOfCode
To view or add a comment, sign in
-
-
JavaScript Logic Practice Today I solved a JavaScript problem “Count Even Numbers in an Array.” The goal was to count how many numbers in the array are even (divisible by 2). Concepts & Methods Used: • Array.isArray() to validate input • for...of loop to iterate through the array • Modulus operator % to check even numbers • typeof and Number.isFinite() to validate numbers This practice helps improve JavaScript logic building and problem-solving skills step by step. I’m working on JavaScript logic every day to improve my coding skills. 💻 #JavaScript #CodingPractice #ProblemSolving #WebDevelopment #SoftwareDevelopment #FrontendDevelopment
To view or add a comment, sign in
-
-
Binary Addition in JavaScript – Manual Approach 👉 Day 92 / Day 93 👈 40🔥 Binary addition manually in JavaScript instead of using built-in conversion methods. The idea is simple: Traverse both binary strings from right to left Add corresponding digits along with carry Maintain carry for the next iteration Build the result string from left #JavaScript #DataStructures #Algorithms #DSA #ProblemSolving #CodingPractice #FrontendDeveloper #InterviewPreparation #100DaysOfCode #Binary
To view or add a comment, sign in
-
-
📌 Mock Interview Question – JavaScript Q: What is catch in JavaScript? In JavaScript, catch is used with try to handle errors in a program. When we write code inside a try block, JavaScript will try to execute it. If an error occurs, the catch block will handle the error so that the program does not stop suddenly. 🔹 Syntax: try { // code that may cause error } catch (error) { // code to handle the error } 🔹 Example: try { let result = x + 10; // x is not defined } catch (error) { console.log("Error occurred:", error.message); } 👉 Output: Error occurred: x is not defined 💡 Why use catch? Prevent program crash Handle errors gracefully Show proper messages to users #JavaScript #WebDevelopment #FrontendDeveloper #CodingJourney #LearningToCode
To view or add a comment, sign in
-
Shallow Copy vs Deep Copy in JavaScript 🧠 Copying objects in JavaScript isn’t always what it seems. Sometimes you copy the value, and sometimes you only copy the reference (memory address). Shallow Copy Creates a new object, but nested objects still point to the same memory location. Example: let arr1 = [1, 2, 3, { value: 10 }]; let arr2 = [...arr1]; If you change the nested object in arr1, it will also change in arr2 because both reference the same object in memory. Deep Copy Creates a completely independent copy of the entire structure. Example: let arr2 = JSON.parse(JSON.stringify(arr1)); Now both arrays exist in separate memory locations, so changes in one won’t affect the other. A small concept… but understanding it can prevent some very confusing bugs in JavaScript. Grateful for the guidance and learning from Devendra Dhote, our instructor. #JavaScript #WebDevelopment #FrontendDevelopment #Coding #LearnInPublic
To view or add a comment, sign in
-
-
🚀 Day 912 of #1000DaysOfCode ✨ Prototype-Based Inheritance in JavaScript JavaScript doesn’t use classical inheritance like many other languages — it follows a prototype-based inheritance model. In today’s post, I’ve explained how prototype-based inheritance works in JavaScript in a simple and structured way. You’ll understand how objects are linked, how properties are shared, and how the prototype chain actually behaves behind the scenes. If you’ve ever been confused about `__proto__`, `prototype`, or how inheritance really works in JS, this post will help you build strong conceptual clarity. 👇 Did prototype inheritance confuse you when you first learned JavaScript? #Day912 #learningoftheday #1000daysofcodingchallenge #FrontendDevelopment #WebDevelopment #JavaScript #React #Next #CodingCommunity #Prototype
To view or add a comment, sign in
-
🚀 JavaScript Concept: Async/Await — Modern Async Made Simple Async/Await is built on top of Promises and makes async code look synchronous. 🔹 Benefits ✔ Cleaner syntax ✔ Easier debugging ✔ Better readability 🔹 Example async function getData() { try { const res = await fetch("https://lnkd.in/dCvdkSsB"); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } } 💡 If Promises are powerful, Async/Await is elegant. Modern JavaScript developers should master this ✔ #JavaScript #AsyncAwait #CleanCode #WebDevelopment
To view or add a comment, sign in
-
JavaScript Practice – Day by Day Improvement Today I practiced a JavaScript logic problem “Array Chunking.” The goal was to split an array into smaller subarrays (chunks) of a given size. Concepts & Methods Used: • for loop for iteration • Array.slice() method to extract subarrays • Incrementing index by chunk size (i += n) for efficient traversal This approach helps break a large array into manageable chunks and improves understanding of array manipulation and problem-solving in JavaScript. I’m focusing on improving my JavaScript logic day by day through consistent practice. 💻 #JavaScript #ProblemSolving #CodingPractice #WebDevelopment #FrontendDevelopment
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