In a Javascript L1 & L2 round the following questions can be asked from interviewer. 1. What is the difference between 'Pass by Value' and 'Pass by Reference'? 2. What is the difference between map and filter ? 3. What is the difference between map() and forEach() 4. What is the difference between Pure and Impure functions? 5. What is the difference between for-in and for-of ? 6. What are the differences between call(), apply() and bind() ? 7. List out some key features of ES6 ? 8. What’s the spread operator in javascript ? 9. What is rest operator in javascript ? 10. What are DRY, KISS, YAGNI, SOLID Principles ? 11. What is temporal dead zone ? 12. Different ways to create object in javascript ? 13. Whats the difference between Object.keys,values and entries 14. Whats the difference between Object.freeze() vs Object.seal() 15. What is a polyfill in javascript ? 16. What is generator function in javascript ? 17. What is prototype in javascript ? 18. What is IIFE ? 19. What is CORS ? 20. What are the different datatypes in javascript ? 21. What are the difference between typescript and javascript ? 22. What is authentication vs authorization ? 23. Difference between null and undefined ? 24. What is the output of 3+2+”7” ? 25. Slice vs Splice in javascript ? 26. What is destructuring ? 27. What is setTimeOut in javascript ? 28. What is setInterval in javascript ? 29. What are Promises in javascript ? 30. What is a callstack in javascript ? 31. What is a closure ? 32. What are callbacks in javascript ? 33. What are Higher Order Functions in javascript ? 34. What is the difference between == and === in javascript ? 35. Is javascript a dynamically typed language or a statically typed language 36. What is the difference between Indexeddb and sessionstorage ? 37. What are Interceptors ? 38. What is Hoisting ? 39. What are the differences let, var and const ? 41. Differences between Promise.all, allSettled, any, race ? 42. What are limitations of arrow functions? 43. What is difference between find vs findIndex ? 44. What is tree shaking in javascrip 45. What is the main difference between Local Storage and Session storage 46. What is eval() 47. What is the difference between Shallow copy and deep copy 48. What are the difference between undeclared and undefined variables 49. What is event bubbling 50. What is event capturing 51. What are cookies 52. typeOf operator 53. What is this in javascript and How it behaves in various scenarios 54. How do you optimize the performance of application 55. What is meant by debouncing and throttling 𝐠𝐞𝐭 𝐞𝐛𝐨𝐨𝐤 𝐰𝐢𝐭𝐡 (detailed 232 ques = 90+ frequently asked Javascript interview questions and answers, 90+ Reactjs Frequent Ques & Answers, 50+ Output based ques & ans, 23+ Coding Questions & ans, 2 Machine coding ques & ans) 𝐄𝐛𝐨𝐨𝐤 𝐋𝐢𝐧𝐤: https://lnkd.in/gJMmH-PF Follow on Instagram : https://lnkd.in/gXTrcaKP #javascriptdeveloper #reactjs #reactnative #vuejsdeveloper #angular #angulardeveloper
JavaScript Interview Questions and Answers
More Relevant Posts
-
🚀 Day 4 of #30DaysOfJavaScript (27 April 2026) Today I explored All Types of Functions in JavaScript (with definitions & examples) আজ আমি JavaScript-এর সব ধরনের Function শিখেছি (definition ও example সহ) 📌 Function (Definition | সংজ্ঞা) 👉 A function is a reusable block of code that performs a specific task. 👉 Function হলো reusable code block যেটা নির্দিষ্ট কাজ করে। 🔹 1. Function Declaration 👉 Defined using function keyword 👉 function keyword দিয়ে define করা হযfunction greet() { console.log("Hello"); } greet(); 🎯 Use: General reusable logic 🔸 2. Function Expression 👉 Function stored in a variable 👉 variable এর ভিতরে function রাখা হয়const greet = function() { console.log("Hi"); }; 🎯 Use: Dynamic function usage, callbacks ⚡ 3. Arrow Function (ES6) 👉 Short syntax using => 👉 shortcut way te function লেখা হয়const add = (a, b) => a + b; 🎯 Use: Clean & short code (React e beshi use) 🔁 4. Callback Function 👉 Function passed as argument to another function 👉 ekta function ke onno function er moddhe pathano hoy function greet(name, callback) { console.log("Hi " + name); callback(); } greet("Fahmida", () => console.log("Done")); 🎯 Use: Async কাজ, event handling 🧠 5. Anonymous Function 👉 Function without a name 👉 function er kono naam thake na setTimeout(function() { console.log("Hello"); }, 1000); 🎯 Use: One-time use, callbacks 🔄 6. IIFE (Immediately Invoked Function) 👉 Runs immediately after definition 👉 define korar sathe sathe run hoy (function() { console.log("Run instantly"); })(); 🎯 Use: Private scope, global variable avoid 🧩 7. Higher-Order Function 👉 Function that takes/returns another function 👉 function jeta onno function ke receive ba return kore function multiplier(x) { return function(y) { return x * y; }; } 🎯 Use: map, filter, reusable logic 🧱 8. Constructor Function 👉 Used to create objects with new 👉 object create korar jonno use hoy function User(name) { this.name = name; } const u1 = new User("Fahmida"); 🎯 Use: Object creation (OOP style) ⚠️ Common Mistakes 👉 Arrow function e this confusion 👉 Forgetting return 👉 Overusing anonymous functions 🔥 Learning 👉 Functions are the heart of JavaScript — everything from React components to APIs depends on them 👉 JavaScript-এর সবচেয়ে powerful concept হলো function #JavaScript #FullStackDeveloper #LearningInPublic #WebDevelopment #30DaysChallenge ়
To view or add a comment, sign in
-
🚀 JavaScript Simplified Series — Day 22 You can select elements… But what’s the use if you can’t **change them?** 🤔 Real power of JavaScript starts when you **manipulate the DOM** 😎 --- ## 🤔 Real Problem Socho tumhare paas ek website hai: ```html id="dm1" <h1 id="title">Hello</h1> <button>Click Me</button> ``` Ab tum chahte ho: 👉 Button click hone par text change ho 👉 New element add ho 👉 Style change ho Ye sab kaise hoga? --- ## 🔥 Solution → DOM Manipulation --- ## 🔹 1. Changing Text ```javascript id="dm2" let heading = document.querySelector("#title") heading.innerText = "Welcome to JavaScript" ``` 👉 Text change ho gaya 😎 --- ## 🔹 2. Changing HTML ```javascript id="dm3" heading.innerHTML = "<span>Hello World</span>" ``` 📌 HTML content bhi change kar sakte ho --- ## 🔹 3. Changing Styles ```javascript id="dm4" heading.style.color = "red" heading.style.backgroundColor = "yellow" ``` 👉 Direct CSS apply kar sakte ho --- ## 🔹 4. Creating New Element ```javascript id="dm5" let newPara = document.createElement("p") newPara.innerText = "This is new paragraph" ``` --- ## 🔹 5. Adding Element to Page ```javascript id="dm6" document.body.appendChild(newPara) ``` 👉 New element page par add ho gaya --- ## 🔹 6. Removing Element ```javascript id="dm7" newPara.remove() ``` 👉 Element delete ho gaya --- ## 🔥 Real Life Example Think of DOM like a **live document 📝** 👉 Text change karo 👉 Naya content add karo 👉 Design update karo Sab kuch JavaScript control karta hai --- ## 🔥 Simple Summary innerText → text change innerHTML → HTML change style → design change createElement → new element appendChild → add element remove → delete element --- ### 💡 Programming Rule **Websites are not static. JavaScript makes them dynamic.** --- If you want to learn JavaScript in a **simple and practical way**, you can follow these YouTube channels: • Rohit Negi • Hitesh Choudhary (Chai aur Code) --- 📌 Series Progress Day 1 → What is JavaScript Day 2 → Variables & Data Types Day 3 → Type Conversion & Operators Day 4 → Truthy & Falsy + Comparison Operators Day 5 → If Else + Switch + Ternary Day 6 → Loops Day 7 → Break + Continue + Nested Loops Day 8 → Functions Basics Day 9 → Arrow + Default + Rest Parameters Day 10 → Callback & Higher Order Functions Day 11 → Arrays Basics Day 12 → Array Methods Day 13 → Array Iteration Day 14 → Advanced Array Methods Day 15 → Objects Basics Day 16 → Object Methods + this Day 17 → Object Destructuring Day 18 → Spread & Rest Day 19 → Advanced Objects Day 20 → DOM Introduction Day 21 → DOM Selectors Day 22 → DOM Manipulation Day 23 → Events (Next Post) --- Follow for more 🚀 #JavaScriptSimplified #javascript #webdevelopment #coding #programming #learninpublic #100DaysOfCode #frontenddevelopment #devcommunity #codingjourney #softwaredeveloper #techcommunity #dailylearning #codeeveryday
To view or add a comment, sign in
-
Ever tried mixing HTML inside JavaScript… and everything just broke? 🤯 Or got weird errors for something that “looks like valid HTML”? That’s where 𝗝𝗦𝗫 𝗶𝗻 𝗥𝗲𝗮𝗰𝘁 changes the game. 🚀 𝗝𝗦𝗫 𝗕𝗮𝘀𝗶𝗰𝘀 — 𝗪𝗿𝗶𝘁𝗶𝗻𝗴 𝗨𝗜 𝗶𝗻𝘀𝗶𝗱𝗲 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 In React, we don’t write traditional HTML. Instead, we use 𝗝𝗦𝗫 (𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗫𝗠𝗟) — a syntax that lets you write HTML-like code inside JavaScript. 👉 It makes UI code more readable and component-driven. 💡 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗝𝗦𝗫 (𝗮𝗻𝗱 𝘄𝗵𝘆 𝘂𝘀𝗲 𝗶𝘁)? JSX is a syntax extension for JavaScript used in React to describe UI. Under the hood: ◦ JSX gets converted into React.createElement() ◦ It helps React understand what UI to render 👉 Why developers love it: ◦ Cleaner and more readable UI code ◦ Combines logic + UI in one place ◦ Reduces manual DOM manipulation 🔍 𝗘𝘅𝗮𝗺𝗽𝗹𝗲: 𝗦𝗶𝗺𝗽𝗹𝗲 𝗝𝗦𝗫 𝗖𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝐺𝑟𝑒𝑒𝑡𝑖𝑛𝑔() { 𝑐𝑜𝑛𝑠𝑡 𝑛𝑎𝑚𝑒 = "𝑆ℎ𝑢𝑏ℎ𝑎𝑚"; 𝑟𝑒𝑡𝑢𝑟𝑛 ( <𝑑𝑖𝑣> <ℎ2>𝐻𝑒𝑙𝑙𝑜, {𝑛𝑎𝑚𝑒} 👋</ℎ2> <𝑝>𝑊𝑒𝑙𝑐𝑜𝑚𝑒 𝑡𝑜 𝑅𝑒𝑎𝑐𝑡 𝐽𝑆𝑋 𝑏𝑎𝑠𝑖𝑐𝑠!</𝑝> </𝑑𝑖𝑣> ); } 🧠 𝗪𝗵𝗮𝘁’𝘀 𝗵𝗮𝗽𝗽𝗲𝗻𝗶𝗻𝗴 𝗵𝗲𝗿𝗲? ◦ {name} → injects JavaScript inside JSX ◦ JSX looks like HTML, but it’s actually JavaScript ◦ The component returns UI that React renders to the DOM 👉 This is declarative UI — you describe what to show, not how to update it ⚠️ 𝗝𝗦𝗫 𝗥𝘂𝗹𝗲𝘀 𝗘𝘃𝗲𝗿𝘆 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿 𝗠𝘂𝘀𝘁 𝗞𝗻𝗼𝘄 1️⃣ 𝗥𝗲𝘁𝘂𝗿𝗻 𝗮 𝘀𝗶𝗻𝗴𝗹𝗲 𝗽𝗮𝗿𝗲𝗻𝘁 𝗲𝗹𝗲𝗺𝗲𝗻𝘁 𝑟𝑒𝑡𝑢𝑟𝑛 ( <𝑑𝑖𝑣> <ℎ1>𝐻𝑒𝑙𝑙𝑜</ℎ1> <𝑝>𝑊𝑜𝑟𝑙𝑑</𝑝> </𝑑𝑖𝑣> ); 2️⃣ 𝗨𝘀𝗲 𝗰𝗹𝗮𝘀𝘀𝗡𝗮𝗺𝗲 𝗶𝗻𝘀𝘁𝗲𝗮𝗱 𝗼𝗳 𝗰𝗹𝗮𝘀𝘀 <𝑑𝑖𝑣 𝑐𝑙𝑎𝑠𝑠𝑁𝑎𝑚𝑒="𝑐𝑜𝑛𝑡𝑎𝑖𝑛𝑒𝑟"></𝑑𝑖𝑣> 3️⃣ 𝗔𝗹𝘄𝗮𝘆𝘀 𝗰𝗹𝗼𝘀𝗲 𝘁𝗮𝗴𝘀 <𝑖𝑚𝑔 𝑠𝑟𝑐="𝑖𝑚𝑎𝑔𝑒.𝑝𝑛𝑔" /> 4️⃣ 𝗨𝘀𝗲 𝗰𝘂𝗿𝗹𝘆 𝗯𝗿𝗮𝗰𝗲𝘀 𝗳𝗼𝗿 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 <ℎ1>{2 + 2}</ℎ1> 5️⃣ 𝗜𝗻𝗹𝗶𝗻𝗲 𝘀𝘁𝘆𝗹𝗲𝘀 𝘂𝘀𝗲 𝗼𝗯𝗷𝗲𝗰𝘁𝘀 <𝑑𝑖𝑣 𝑠𝑡𝑦𝑙𝑒={{ 𝑐𝑜𝑙𝑜𝑟: "𝑏𝑙𝑢𝑒", 𝑓𝑜𝑛𝑡𝑆𝑖𝑧𝑒: "18𝑝𝑥" }}></𝑑𝑖𝑣> 🏗️ 𝗥𝗲𝗮𝗹-𝘄𝗼𝗿𝗹𝗱 𝘂𝘀𝗲 𝗰𝗮𝘀𝗲𝘀 JSX is used everywhere in React apps: ◦ Building reusable UI components ◦ Rendering dynamic data (API responses) ◦ Conditional rendering (login/logout UI) ◦ Mapping lists (products, users, posts) 📌 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆𝘀 ✔ JSX makes UI code readable and expressive ✔ It combines JavaScript logic with HTML-like syntax ✔ Following JSX rules avoids common beginner mistakes Once you get comfortable with JSX… React starts to feel natural. 💬 Do you find JSX intuitive or confusing when you first learned it? 🚀 Follow Shubham Kumar Raj for more such content. #JavaScript #WebDevelopment #Frontend #CodingTips #100DaysOfCode #codinginterview #learnjavascript #programming #interviewprep #CareerGrowth #SowftwareEngineering #OpenToWork #ReactJS #FrontendDevelopment #Coding
To view or add a comment, sign in
-
-
✨ 𝗪𝗿𝗶𝘁𝗲 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗦𝘁𝗿𝗶𝗻𝗴𝘀 𝗟𝗶𝗸𝗲 𝗔 𝗛𝘂𝗺𝗮𝗻 ⤵️ Template Literals in JavaScript: Write Strings Like a Human ⚡ 🔗 𝗥𝗲𝗮𝗱 𝗵𝗲𝗿𝗲: https://lnkd.in/d_HhAEsM 𝗧𝗼𝗽𝗶𝗰𝘀 𝗰𝗼𝘃𝗲𝗿𝗲𝗱 ✍🏻: ⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺ ⇢ Why string concatenation becomes messy in real apps ⇢ Template literals — the modern way to write strings ⇢ Embedding variables & expressions using ${} ⇢ Multi-line strings without \n headaches ⇢ Before vs After — readability transformation ⇢ Real-world use cases: HTML, logs, queries, error messages ⇢ Tagged templates (advanced but powerful concept) ⇢ How interpolation works under the hood ⇢ Tradeoffs & common mistakes developers make ⇢ Writing cleaner, more readable JavaScript Thanks Hitesh Choudhary Sir & Piyush Garg Sir, and the amazing Chai Aur Code community 🙌 #ChaiAurCode #JavaScript #WebDevelopment #Frontend #Programming #CleanCode #Hashnode
To view or add a comment, sign in
-
Symbols were the way to create private fields in JavaScript before private fields were a standard language feature. And in some cases, they're still the best option out there for performance purposes. How do they work? Instead of creating a regular string like "my-key", you create a symbol like `Symbol("my-key")`. The value that `Symbol` returns is unique, meaning that `Symbol("my-key") !== Symbol("my-key")`. This means that a developer can't access your class field using `obj[Symbol("my-key")]`. Rather, only those who have a reference to the uniquely-created symbol can access the field. Consider this code: const key = Symbol("my-key"); obj[key] = "value"; // ... export { obj }; Here, we export `obj`, but not `key`, meaning only we have the ability to read and write the value (kind of). The `ws` Node.js package has been using this clever approach for a long time. Since private fields are a native feature in JS now, there usually isn't a reason to take this approach. However, you might still find it useful when making Custom Elements, or other kinds of classes that need to use event listeners (e.g., in Node). If you remember, I made a post wayyyyyy back explaining how static event listeners provide the best performance in JavaScript. Of course, static event listeners prevent you from accessing `this`. And if you need access to a private field in your event listener, you'll be forced to use `this#key` and lose the performance boost. This is where Symbols shine! Instead of accessing private data through `this#key`, you can access it through `instance[symbolKey]`! As long as you have access to the symbol in your class's file, you'll be able to access data that the rest of the outside world can't (kind of). If you've been catching my "kind of"s, there's a caveat here: JS gives developers a way to inspect all of an object's Symbols. Generally speaking, most developers don't know about the existence of the global function that allows this, and many don't even know about Symbols at all. Plus, Symbol-based properties don't show up in IDE IntelliSense as devs type. So Symbol-based fields are semi-private! Nonetheless, Symbol-based properties are not "perfectly private". You might still choose to use them for performance purposes. But the adventurous devs who love scrutinizing code to find and use the `_DO_NOT_USE` properties will still be able to have their way. As with all things, this is about trade-offs. In my Combobox component, I've mostly been using private fields. But I've reached for Symbols in cases where I really wanted to keep using static event handlers. ComboBoxedIn Logs #17 (No, I haven't forgotten about these.)
To view or add a comment, sign in
-
🚀 JavaScript Simplified Series — Day 20 Till now… you’ve learned JavaScript concepts. But here’s the real question 👇 👉 How does JavaScript actually interact with a website? How does a button click work? How does text change on screen? How does a form submit? This is where DOM comes in. 🔥 What is DOM? DOM stands for: 👉 Document Object Model Simple words me: DOM is a tree-like structure of your HTML page which JavaScript can read and modify. 🔹 Let’s Understand with a Real Example Imagine this HTML: <body> <h1>Hello</h1> <button>Click Me</button> </body> Browser ise internally convert karta hai: Document └── body ├── h1 └── button 👉 Ye pura structure hi DOM hai 🔹 Why DOM is Important? Without DOM: ❌ JavaScript kuch change nahi kar sakta ❌ Website static rahegi With DOM: ✅ Text change kar sakte ho ✅ Elements add/remove kar sakte ho ✅ Events handle kar sakte ho 🔹 Accessing DOM using JavaScript let heading = document.querySelector("h1") console.log(heading) 👉 JavaScript ne HTML element access kar liya 🔹 Changing Content let heading = document.querySelector("h1") heading.innerText = "Welcome to JavaScript" 👉 Screen par text change ho jayega 😎 🔹 Button Click Example let button = document.querySelector("button") button.addEventListener("click", function() { alert("Button Clicked!") }) 👉 User click kare → action trigger hota hai 🔥 Real Life Example Think of a website like a remote-controlled machine 🎮 HTML → structure CSS → design JavaScript (DOM) → control 👉 DOM is the bridge between JavaScript and HTML 🔥 Simple Summary DOM → HTML ka structure JavaScript → DOM ko control karta hai Result → Interactive website 💡 Programming Rule If you can control the DOM, you can control the entire website. If you want to learn JavaScript in a simple and practical way, you can follow these YouTube channels: • Rohit Negi •Hitesh Choudhary (Chai aur Code) 📌 Series Progress Day 1 → What is JavaScript Day 2 → Variables & Data Types Day 3 → Type Conversion & Operators Day 4 → Truthy & Falsy + Comparison Operators Day 5 → If Else + Switch + Ternary Day 6 → Loops Day 7 → Break + Continue + Nested Loops Day 8 → Functions Basics Day 9 → Arrow + Default + Rest Parameters Day 10 → Callback & Higher Order Functions Day 11 → Arrays Basics Day 12 → Array Methods Day 13 → Array Iteration Day 14 → Advanced Array Methods Day 15 → Objects Basics Day 16 → Object Methods + this Day 17 → Object Destructuring Day 18 → Spread & Rest Day 19 → Advanced Objects Day 20 → DOM Introduction Day 21 → Selecting Elements (Next Post) Follow for more 🚀 #JavaScriptSimplified #javascript #webdevelopment #coding #programming #learninpublic #100DaysOfCode #frontenddevelopment #devcommunity #codingjourney #softwaredeveloper #techcommunity #dailylearning #codeeveryday
To view or add a comment, sign in
-
Lately, I’ve been going deeper into JavaScript coercion, and the more I study it, the less random JavaScript feels. A lot of behaviour that looks strange at first starts making sense once you realise that JavaScript is following rules defined in the ECMAScript specification. Recently, I focused on the abstract operations behind conversion, especially: - ToNumber - StringToNumber - ToString - ToPrimitive - OrdinaryToPrimitive One of the biggest takeaways for me is that JavaScript does not just “guess” what to do with values. It follows a defined process depending on the operation being performed. For example: - `"5" - 1` works because subtraction expects numbers. - `Number("")` becomes `0`. - `Number(undefined)` becomes `NaN`. - `ToNumber(BigInt)` throws an error, but `ToString(BigInt)` works. - When an object is involved, JS first tries to extract a primitive value before continuing coercion The part I found especially interesting was object-to-primitive conversion. If JavaScript encounters an object in a coercion context, it first checks for `Symbol.toPrimitive`. If that is not available, it falls back to `OrdinaryToPrimitive`, where the order of calling `toString()` and `valueOf()` depends on the hint being used: - string hint → toString() first - number hint → valueOf() first I also learned more about why string-to-number conversion behaves the way it does: - Number("25") gives 25 - Number(" 25 ") also gives 25 - Number("Infinity") gives Infinity - Number("1_000") gives NaN - Number("10n") gives NaN What is changing my understanding the most is this: - Instead of memorising “weird JavaScript behaviour”, I’m now trying to ask: 1. What operation is being performed? 2. What type of value does that operation expect? 3. Which abstract operation is JavaScript using behind the scenes? That mindset makes the language much easier to reason about. I’ve also been maintaining detailed notes on what I’m learning. If anyone wants to go deeper into these topics, I’ve uploaded them here: GitHub repo: https://lnkd.in/ephuZ-w6 #JavaScript #TypeScript #WebDevelopment #SoftwareEngineering #ECMAScript #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 𝗟𝗲𝘃𝗲𝗹𝗶𝗻𝗴 𝘂𝗽 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗿𝗲𝗮𝗱𝗮𝗯𝗶𝗹𝗶𝘁𝘆 𝘄𝗶𝘁𝗵 𝗧𝗲𝗺𝗽𝗹𝗮𝘁𝗲 𝗟𝗶𝘁𝗲𝗿𝗮𝗹𝘀 String concatenation in JavaScript can quickly turn messy—especially as logic scales. That’s where template literals step in and change the game. I've put together a detailed blog breaking this down: “𝗠𝗮𝘀𝘁𝗲𝗿𝗶𝗻𝗴 𝗧𝗲𝗺𝗽𝗹𝗮𝘁𝗲 𝗟𝗶𝘁𝗲𝗿𝗮𝗹𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁: 𝗦𝗮𝘆 𝗚𝗼𝗼𝗱𝗯𝘆𝗲 𝘁𝗼 𝗦𝘁𝗿𝗶𝗻𝗴 𝗖𝗼𝗻𝗰𝗮𝘁𝗲𝗻𝗮𝘁𝗶𝗼𝗻 𝗡𝗶𝗴𝗵𝘁𝗺𝗮𝗿𝗲𝘀” Link: https://lnkd.in/dQdeSyxh 🔍 What the blog covers: 🔹 Why traditional string concatenation becomes hard to maintain 🔹 How template literals improve readability and developer experience 🔹 Practical use-cases with expressions and multi-line strings 🔹 Writing cleaner, more scalable JavaScript code If you're working with JavaScript, this is a small shift that delivers a big productivity gain. Grateful for the continuous learning ecosystem and guidance from: Hitesh Choudhary Piyush Garg Anirudh J. Chai Aur Code Akash Kadlag Suraj Kumar Jha Nikhil Rathore Jay Kadlag DEV Community #JavaScript #WebDevelopment #TechnicalWriting #CleanCode #LearningInPublic #Chaicode #Cohort
To view or add a comment, sign in
-
#js #19 **Optional Chaining in Javascript** Optional Chaining (?.) in JavaScript is used to safely access nested properties without causing errors if something is null or undefined. 🔹 Why We Need It Without optional chaining: const user = null; console.log(user.name); // ❌ Error: Cannot read property 'name' 👉 This crashes your code. ✅ With Optional Chaining const user = null; console.log(user?.name); // undefined ✅ (no error) 👉 If user is null or undefined, it stops and returns undefined 🔹 Syntax obj?.propertyobj?.[key]obj?.method() ✅ Examples 📌 1. Nested Objects const user = { profile: { name: "Navnath" }}; console.log(user?.profile?.name); // Navnath console.log(user?.address?.city); // undefined 📌 2. Function Calls const user = { greet() { return "Hello"; }}; console.log(user.greet?.()); // Hello console.log(user.sayHi?.()); // undefined (no error) 📌 3. Arrays const arr = [1, 2, 3]; console.log(arr?.[0]); // 1 console.log(arr?.[5]); // undefined 🔥 Real Use Case (Very Common) const response = { data: { user: { name: "Navnath" } }}; const name = response?.data?.user?.name; 👉 Avoids writing multiple checks like: if (response && response.data && response.data.user) ... ⚠️ Important Points ❌ Doesn’t Work on Undeclared Variables console.log(user?.name); // ❌ if user is not defined at all ⚠️ Stops Only on null / undefined const obj = { value: 0 }; console.log(obj?.value); // 0 ✅ (not skipped) 🔥 Combine with Nullish Coalescing (??) const user = {}; const name = user?.name ?? "Guest"; console.log(name); // Guest 🧠 Easy Memory Trick ?. → "If exists, then access" Otherwise → return undefined, don’t crash #Javascript #ObjectOrientedProgramming #SoftwareDevelopment
To view or add a comment, sign in
-
A step-by-step example of how I'll often use LLMs in practice when I'm writing JavaScript. (I use Codex, GitHub Co-Pilot and Claude Code via a variety of IDEs and other interfaces, on occasion...) This morning, I needed to computationally convert any number of URL slugs like: new-york-city central-park manhattan-island hudson-river etc. to title case: New York City Central Park Manhattan Island Hudson River In PHP, there's a dedicated function for converting to title case: ucwords() But in JavaScript, there isn't. Here's my thought process in steps: 1) I forget what it is off the top of my head, but there must be a fairly simple Regex which will convert to title case. I'll search for it and find a Stack Overflow page from 2011 or something... 2) Oh no, hang on, I can ask an LLM instead. That will be quicker. 3) Although. How difficult can this be? Why don't I at least start typing something and see if I can do it in a minute or two without resorting to a Language Model? 4) I'll name the function entitleText() and I'll give it a single parameter, textString: function entitleText (textString) { [...] } 5) Here we go then. I'll split the text into an array before I apply the regex: let textArray = textString.split('-'); 6) And then I can rewrite each element of the array... textArray = textArray.map((textElement) => textElement.replace(//g, '') [... hmmm...] 7) Oh! This is easy. I don't even need a regex. I can capitalise the first letter with textElement[0].toUpperCase() and then I can add the rest: + textElement.slice(1) 8) So now I have a complete function: const entitleText = (textString) => { let textArray = textString.split('-'); textArray = textArray.map((textElement) => textElement[0].toUpperCase() + textElement.slice(1)); return textArray.join(' '); } which I can shorten to a one-liner if need be (left as an exercise to the reader). Ta-da. That took 2mins. Wasn't the LLM useful?
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