Console.log([1,2,3] + [4,5,6]). What is the output? 🤔 💬 Comment your answer first… then click “more” 👇 Most developers think the result is: [1,2,3,4,5,6] ❌ Nope 😏 In JavaScript the output is: "1,2,34,5,6" 💥 👉 Data type: string 👉 Why? Arrays convert to strings before using +. Then JavaScript concatenates the strings. 🔥 Rule: + with arrays → string concatenation Did you guess the correct output and data type? 😄 #javascript #codingtips #programming #developer #webdev #100daysofcode
Durai R’s Post
More Relevant Posts
-
'𝘄𝗼𝗿𝗸𝗲𝗿_𝘁𝗵𝗿𝗲𝗮𝗱𝘀' 𝗱𝗼 𝗻𝗼𝘁 𝗵𝗮𝘃𝗲 𝘁𝗵𝗲 𝘀𝗮𝗺𝗲 𝗝𝗦 𝗵𝗲𝗮𝗽 𝗮𝘀 𝘁𝗵𝗲 𝗺𝗮𝗶𝗻 𝘁𝗵𝗿𝗲𝗮𝗱. As mentioned above, 𝗪𝗼𝗿𝗸𝗲𝗿𝘀 𝗿𝘂𝗻 𝗶𝗻𝘀𝗶𝗱𝗲 𝘁𝗵𝗲𝗶𝗿 𝗼𝘄𝗻 𝗩𝟴 𝗶𝘀𝗼𝗹𝗮𝘁𝗲 which has 𝗮 𝘀𝗲𝗽𝗮𝗿𝗮𝘁𝗲 𝗺𝗲𝗺𝗼𝗿𝘆 𝗹𝗶𝗺𝗶𝘁. Therefore, raising the memory limit for the main process via `--max-old-space-size` does not mean that the 𝗪𝗼𝗿𝗸𝗲𝗿𝘀 𝗴𝗲𝘁 𝗮𝗱𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹 𝗺𝗲𝗺𝗼𝗿𝘆 𝘁𝗼𝗼. It makes a difference in case when the application does something heavy - like parsing PDF files. We could 𝗱𝗲𝗳𝗶𝗻𝗲 𝘁𝗵𝗲 𝗵𝗲𝗮𝗽 𝘀𝗶𝘇𝗲 𝘁𝗵𝗮𝘁 𝘁𝗵𝗲 𝗪𝗼𝗿𝗸𝗲𝗿 𝘄𝗼𝘂𝗹𝗱 𝘂𝘀𝗲 import { Worker } from "worker_threads"; new Worker(new URL("./heavy-job-worker.js", import.meta.url), { resourceLimits: { maxOldGenerationSizeMb: 4096, }, }); When working with large PDF files and 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗶𝗻𝗴 𝗵𝗲𝗮𝘃𝘆 𝗼𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀 𝗹𝗶𝗸𝗲 𝗱𝗮𝘁𝗮 𝗽𝗿𝗼𝗰𝗲𝘀𝘀𝗶𝗻𝗴, this could be useful. #NodeJS #JavaScript #BackendDevelopment #SoftwareEngineering #WebDevelopment #V8 #Performance #Scalability #Multithreading #WorkerThreads #SystemDesign #Programming #Coding
To view or add a comment, sign in
-
Why you should NEVER delete items from an array while looping through it. I encountered a classic JavaScript "gotcha" that can catch even experienced developers off guard. Consider this code snippet: const numbers = [2, 4, 6, 8, 10]; numbers.forEach((num, index) => { if (num % 2 === 0) { numbers.splice(index, 1); } }); console.log(numbers); Pop Quiz: What does console.log(numbers) output? A) [] (Empty array - all evens removed) B) [4, 8] C) [2, 4, 6, 8, 10] D) ReferenceError The answer may not be what you'd expect. In fact, if you run this, you'll find that half of your data is still there! I've explained WHY this happens (and the 2-line fix) in the first comment. Check it out to avoid this silent bug in your next pull request. #JavaScript #WebDevelopment #CodingTips #CleanCode #SoftwareEngineering
To view or add a comment, sign in
-
JavaScript Logical Series – Day 1 👉 What will be the output? console.log(1 + "2" + "2"); console.log(1 + +"2" + "2"); console.log(1 + -"1" + "2"); console.log(+"1" + "1" + "2"); Output : 122 32 02 112 Explanation • "2" → string → concatenation happens • +"2" → converts string to number • -"1" → converts to number (-1) • Order of operations matters 🔥 Key Point JavaScript type coercion can change output unexpectedly. Always be careful with + operator. #JavaScript #NodeJS #WebDevelopment #Programming #CodingChallenge #FrontendDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
Everyone jokes that the hardest part of programming is naming things, but honestly... it's just the truth. I can spin up a backend, connect a database, and get API routes working fast. But then I'll sit there for minutes completely paralyzed trying to decide if an array should be users, userList, userData, or userArray. (And let's not even talk about trying to name CSS wrapper divs). What’s the worst or weirdest variable name you’ve ever run into in a codebase? I know you guys have seen some bad ones 😂 #webdev #javascript #programming #developerlife
To view or add a comment, sign in
-
🚀 Mastering the Basics of JavaScript! From understanding variables to working with loops, functions, and events — these notes cover the core building blocks of web development 💻 📌 Key Takeaways: • Introduction to JavaScript & its real-world use • Variables, Data Types & Operators • Conditional Statements & Loops • Functions & Events handling • Arrays, Objects & Core Concepts Strong fundamentals = Strong developer 🔥 #JavaScript #WebDevelopment #CodingJourney #Programming #LearnToCode #DeveloperSkills #TechLearning #FrontendDevelopment
To view or add a comment, sign in
-
For vs. While: Which loop wins? 🔄 I just coded a battery drain simulator to test my JavaScript logic. Here’s the rule of thumb I used: Use FOR when you know the number of laps (e.g., "Loop 10 times"). Use WHILE when you’re waiting for a result (e.g., "Loop until the battery hits 0"). In this code, since the battery drop is random, I don't know the number of laps—making the while loop the perfect tool for the job. #Coding #JavaScript #WebDev #Logic
To view or add a comment, sign in
-
-
In this lesson, I shared the basics of variables and data types in JavaScript. These are essential concepts that help store and manage data in any program. Practicing simple examples in VS Code makes it easier to understand how values work and how JavaScript handles different types of data. #JavaScript #WebDevelopment #FrontendDevelopment #CodingJourney #LearnJavaScript #Developers #VSCode #ProgrammingBasics
To view or add a comment, sign in
-
𝗤𝘂𝗶𝗰𝗸 𝘁𝗶𝗽: 𝗡𝗲𝘃𝗲𝗿 𝗿𝗲𝘁𝘂𝗿𝗻 𝗻𝘂𝗹𝗹. 𝗥𝗲𝘁𝘂𝗿𝗻 𝗲𝗺𝗽𝘁𝘆 𝗮𝗿𝗿𝗮𝘆𝘀. ✅ Stop returning null when a list has no results. Return an empty array instead. 𝗕𝗮𝗱: function getUsers() { return users.length > 0 ? users : null; } 𝗚𝗼𝗼𝗱: function getUsers() { return users || []; } 𝗪𝗵𝘆 𝗶𝘁 𝗺𝗮𝘁𝘁𝗲𝗿𝘀: ❌ Null forces every caller to check before iterating ❌ Leads to "Cannot read property of null" crashes ❌ Creates defensive code everywhere ❌ Makes chaining operations impossible ✅ Empty arrays can be iterated safely (zero loops, no crash) ✅ Works with map, filter, reduce without checks ✅ Cleaner code throughout your application Same applies to objects: return {} instead of null when appropriate. Let your data structures be forgiving. Your team will thank you. 🙏 . . . #JavaScript #BestPractices #CleanCode #WebDevelopment #Programming
To view or add a comment, sign in
-
-
This VS Code extension takes JSON visualisation to the next level! 🔥 Turn complex JSON into a clean, interactive graph with a single click, no more digging through raw data! ✨ Hope this helps ✅ Do Like 👍 & Repost 🔄 Follow Ahmed Ali Asif 🌟 for the most amazing content related to Programming & Web Development 💎 #html #css #javascript #100daysofcode #webdevelopment #programming
To view or add a comment, sign in
-
var vs let vs const — The Real Differences If you're still reaching for `var` by default, this one's for you. Three keywords. Three very different behaviors. var • Function-scoped (ignores block scope) • Can be redeclared in the same scope • Hoisted and initialized as undefined • Legacy. Avoid in new code. let • Block-scoped • Can be reassigned, cannot be redeclared • Hoisted but not initialized (Temporal Dead Zone) • Use it when a value needs to change. const • Block-scoped • Cannot be reassigned or redeclared • Same hoisting behavior as let • Use it by default. Your future self will thank you. Rule of thumb: → const by default → let when you must reassign → var — don't Next post: Data Types — all seven, with the typeof null trap. Follow the series. #JavaScript #WebDevelopment #Frontend #CleanCode #NodeJS #SoftwareEngineering #WebDev #CodingTips #ES6 #LearnJavaScript #Programming #Coder #FullStackDeveloper #ReactJS #TypeScript #100DaysOfCode #DeveloperCommunity #TechTips #CodeNewbie #ProgrammingLife
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