<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Md Forhad Sarkar on Medium]]></title>
        <description><![CDATA[Stories by Md Forhad Sarkar on Medium]]></description>
        <link>https://medium.com/@mdforhadsarker?source=rss-60d6013110ba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pgdqfIkX7GLwcDv01yFxZA.jpeg</url>
            <title>Stories by Md Forhad Sarkar on Medium</title>
            <link>https://medium.com/@mdforhadsarker?source=rss-60d6013110ba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:09:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mdforhadsarker/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Write about how a design sprint would help you as a new designer.]]></title>
            <link>https://mdforhadsarker.medium.com/write-about-how-a-design-sprint-would-help-you-as-a-new-designer-a304dfb17a16?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/a304dfb17a16</guid>
            <category><![CDATA[design-sprint]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[ux-research]]></category>
            <category><![CDATA[ux-design-process]]></category>
            <category><![CDATA[ux-design]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Tue, 17 Jun 2025 15:19:35 GMT</pubDate>
            <atom:updated>2025-06-17T15:19:35.709Z</atom:updated>
            <content:encoded><![CDATA[<h3>Write about how a design sprint would help you as a new designer. What are some of the benefits of design sprint phases? What phase are you most interested in participating in and why?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6aD32vRNVySwStvC6tDTmA.png" /></figure><h3>How a Design Sprint Helps Me as a New Designer</h3><ol><li><strong>Clear Structure and Focus:</strong><br> As someone new to design, it can be overwhelming to know where to start or how to approach complex problems. A design sprint offers a structured framework that guides you step-by-step — from understanding the problem to testing solutions — making the design process feel more manageable and purposeful.</li><li><strong>Rapid Learning and Feedback:</strong><br> Instead of spending weeks or months working on a solution that might not work, design sprints allow me to test ideas quickly and gather user feedback early. This speeds up the learning process and helps me grow as a designer by showing me what works and what doesn’t in the real world.</li><li><strong>Collaboration and Communication:</strong><br> Working closely with teammates from different roles (product managers, developers, marketers, etc.) during a sprint helps improve my communication and collaboration skills. It also teaches me how to explain and defend design choices, which is crucial for career development.</li><li><strong>Hands-On Experience:</strong><br> Every phase of the sprint encourages active participation. I get to sketch ideas, build low-fidelity prototypes, and even observe user testing. This hands-on experience builds confidence and sharpens my practical design skills.</li></ol><h3>Benefits of Design Sprint Phases</h3><p>Each phase of a design sprint brings unique advantages:</p><ul><li><strong>Understand (Day 1):</strong> Gain a deep understanding of the problem space and align the team on a shared goal.</li><li><strong>Sketch (Day 2):</strong> Explore multiple solutions quickly, improving creative thinking and idea generation.</li><li><strong>Decide (Day 3):</strong> Learn how to evaluate ideas objectively and focus on what’s most impactful.</li><li><strong>Prototype (Day 4):</strong> Practice turning ideas into tangible, testable designs without the pressure of perfection.</li><li><strong>Test (Day 5):</strong> Get real user feedback and learn how users interact with your design.</li></ul><h3>The Phase I’m Most Interested In: Prototype</h3><p>I’m most excited about the <strong>Prototype phase</strong> because this is where ideas start to become real. Seeing a concept come to life, even in a rough form, is incredibly rewarding. It’s a chance to explore tools like Figma or Adobe XD, build interactive mockups, and visually communicate ideas. As a visual thinker and builder, this phase pushes my creativity while improving my technical skills.</p><h3>Final Thoughts</h3><p>Participating in a design sprint is like a crash course in real-world design thinking. It helps me develop problem-solving skills, work efficiently under pressure, and create user-centered solutions. As a new designer, it offers the perfect mix of learning, collaboration, and practical application that sets the foundation for a strong design career.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a304dfb17a16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[40 most asked DSA questions to clear your next interview :]]></title>
            <link>https://mdforhadsarker.medium.com/40-most-asked-dsa-questions-to-clear-your-next-interview-56eb525511f7?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/56eb525511f7</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[questions]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[sad]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Sun, 12 Jan 2025 07:09:46 GMT</pubDate>
            <atom:updated>2025-01-12T07:09:46.663Z</atom:updated>
            <content:encoded><![CDATA[<h3>40 most asked DSA questions to clear your next interview :</h3><p>Save this post, you will need it during interviews.</p><ol><li>Reverse a linked list.</li></ol><pre>class Node {<br>  constructor(data) {<br>    this.data = data;<br>    this.next = null;<br>  }<br>}<br><br>function reverseLinkedList(head) {<br>  let prev = null;<br>  let current = head;<br><br>  while (current) {<br>    let nextNode = current.next;<br>    current.next = prev;<br>    prev = current;<br>    current = nextNode;<br>  }<br><br>  return prev;<br>}</pre><p>2. Find the middle element of a linked list.</p><pre>function findMiddle(head) {<br>  let slow = head;<br>  let fast = head;<br><br>  while (fast &amp;&amp; fast.next) {<br>    slow = slow.next;<br>    fast = fast.next.next;<br>  }<br><br>  return slow.data;<br>}j</pre><p>3. Implement a stack using arrays/linked list.</p><h4>Using Arrays:</h4><pre>class Stack {<br>  constructor() {<br>    this.stack = [];<br>  }<br><br>  push(data) {<br>    this.stack.push(data);<br>  }<br><br>  pop() {<br>    if (this.isEmpty()) {<br>      return &quot;Stack is empty&quot;;<br>    }<br>    return this.stack.pop();<br>  }<br><br>  isEmpty() {<br>    return this.stack.length === 0;<br>  }<br>}</pre><p>4. Implement a queue using arrays/linked list.</p><pre>class Queue {<br>  constructor() {<br>    this.queue = [];<br>  }<br><br>  enqueue(data) {<br>    this.queue.push(data);<br>  }<br><br>  dequeue() {<br>    if (this.isEmpty()) {<br>      return &quot;Queue is empty&quot;;<br>    }<br>    return this.queue.shift();<br>  }<br><br>  isEmpty() {<br>    return this.queue.length === 0;<br>  }<br>}</pre><p>5. Find the factorial of a number using recursion.</p><pre>function factorial(n) {<br>  if (n === 0 || n === 1) {<br>    return 1;<br>  }<br>  return n * factorial(n - 1);<br>}</pre><p>6. Implement binary search in an array.</p><pre>function binarySearch(arr, target) {<br>  let left = 0;<br>  let right = arr.length - 1;<br><br>  while (left &lt;= right) {<br>    let mid = Math.floor((left + right) / 2);<br><br>    if (arr[mid] === target) {<br>      return mid;<br>    } else if (arr[mid] &lt; target) {<br>      left = mid + 1;<br>    } else {<br>      right = mid - 1;<br>    }<br>  }<br><br>  return -1;<br>}</pre><p>7. Find the largest/smallest element in an array.</p><pre>function findLargest(arr) {<br>  return Math.max(...arr);<br>}<br><br>function findSmallest(arr) {<br>  return Math.min(...arr);<br>}</pre><p>8. Implement merge sort.</p><pre>function mergeSort(arr) {<br>  if (arr.length &lt;= 1) {<br>    return arr;<br>  }<br><br>  const mid = Math.floor(arr.length / 2);<br>  const left = mergeSort(arr.slice(0, mid));<br>  const right = mergeSort(arr.slice(mid));<br><br>  return merge(left, right);<br>}<br><br>function merge(left, right) {<br>  const result = [];<br>  let i = 0, j = 0;<br><br>  while (i &lt; left.length &amp;&amp; j &lt; right.length) {<br>    if (left[i] &lt; right[j]) {<br>      result.push(left[i]);<br>      i++;<br>    } else {<br>      result.push(right[j]);<br>      j++;<br>    }<br>  }<br><br>  return result.concat(left.slice(i)).concat(right.slice(j));<br>}</pre><p>9. Implement quick sort.</p><pre>function quickSort(arr) {<br>  if (arr.length &lt;= 1) {<br>    return arr;<br>  }<br><br>  const pivot = arr[Math.floor(arr.length / 2)];<br>  const left = arr.filter(x =&gt; x &lt; pivot);<br>  const middle = arr.filter(x =&gt; x === pivot);<br>  const right = arr.filter(x =&gt; x &gt; pivot);<br><br>  return [...quickSort(left), ...middle, ...quickSort(right)];<br>}</pre><p>10. Detect a cycle in a linked list.</p><pre>function detectCycle(head) {<br>  let slow = head;<br>  let fast = head;<br><br>  while (fast &amp;&amp; fast.next) {<br>    slow = slow.next;<br>    fast = fast.next.next;<br><br>    if (slow === fast) {<br>      return true;<br>    }<br>  }<br><br>  return false;<br>}</pre><p>11. Find the intersection point of two linked lists.<br>12. Check if a binary tree is a binary search tree (BST).<br>13. Print all leaf nodes of a binary tree.<br>14. Reverse a binary tree.<br>15. Find the height of a binary tree.<br>16. Implement depth-first search (DFS) on a graph.<br>17. Implement breadth-first search (BFS) on a graph.<br>18. Check if a graph is connected.<br>19. Implement Dijkstra’s algorithm for shortest path.<br>20. Implement Prim’s algorithm for minimum spanning tree.<br>21. Implement Kruskal’s algorithm for minimum spanning tree.<br>22. Find the longest common subsequence of two strings.<br>23. Find the longest increasing subsequence of an array.<br>24. Implement the Knuth–Morris–Pratt (KMP) algorithm for string matching.<br>25. Implement the Rabin-Karp algorithm for string matching.<br>26. Check if a string is a palindrome.<br>27. Check if two strings are anagrams of each other.<br>28. Find the next greater element in an array.<br>29. Find the kth smallest/largest element in an array.<br>30. Find the median of two sorted arrays.<br>31. Implement a trie (prefix tree).<br>32. Find all subsets of a set.<br>33. Find all permutations of a string.<br>34. Implement the Josephus Problem.<br>35. Implement an LRU (Least Recently Used) Cache.<br>36. Find the longest palindrome substring in a string.<br>37. Implement a priority queue.<br>38. Implement a hashmap (dictionary).<br>39. Count the number of inversions in an array.<br>40. Find the shortest path in a maze.</p><p>Save for Yourself &amp; Share to help others :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56eb525511f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[how to design code snippet ? 2025]]></title>
            <link>https://mdforhadsarker.medium.com/how-to-design-code-snippet-2025-86b6d3ab8be8?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/86b6d3ab8be8</guid>
            <category><![CDATA[prgramming]]></category>
            <category><![CDATA[website]]></category>
            <category><![CDATA[code-snippet]]></category>
            <category><![CDATA[tools]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Sun, 12 Jan 2025 05:57:26 GMT</pubDate>
            <atom:updated>2025-01-12T05:57:26.985Z</atom:updated>
            <content:encoded><![CDATA[<h3>how to design code snippet ? 2025</h3><p>Designing a code snippet involves formatting and styling your code to make it clear, readable, and visually appealing. Whether for documentation, a presentation, or a website, here are some tips and tools to design a code snippet effectively:</p><h3>1. Use Syntax Highlighting</h3><p>Syntax highlighting makes your code easier to read by color-coding keywords, variables, strings, and comments. This is especially important for sharing snippets in documentation or blogs.</p><h4>Tools:</h4><ul><li><strong>Code Blocks in Markdown</strong>:</li></ul><pre>```javascript<br>function greet(name) {<br>    return `Hello, ${name}!`;<br>}<br>console.log(greet(&quot;John&quot;));</pre><pre>Many platforms like GitHub, Notion, and Markdown editors support this.<br><br></pre><ul><li><strong>Highlight.js</strong>: <a href="https://highlightjs.org/">https://highlightjs.org</a><br>A lightweight library to add syntax highlighting in websites dynamically.</li><li><strong>Prism.js</strong>: <a href="https://prismjs.com/">https://prismjs.com</a><br>A customizable library for highlighting code on the web.</li></ul><h3>2. Use Code Editors for Styling</h3><p>Tools like VS Code, JetBrains IDEs, or Sublime Text offer built-in styling options. You can take screenshots of your code or export it as styled snippets.</p><h4>Plugins for Code Styling:</h4><ul><li><strong>Polacode</strong> (VS Code): Creates beautiful screenshots of code snippets.</li><li><strong>Carbon</strong> (<a href="https://carbon.now.sh/">https://carbon.now.sh</a>): A popular web app for generating stylish code snippet images.</li></ul><h3>3. Add Borders or Shadows</h3><p>Use CSS or tools to add subtle borders or shadows around your snippet to give it a clean look.</p><h4>Example with CSS:</h4><pre>&lt;pre style=&quot;background: #f5f5f5; border: 1px solid #ddd; padding: 15px; border-radius: 5px; font-family: &#39;Courier New&#39;, monospace;&quot;&gt;<br>function sum(a, b) {<br>    return a + b;<br>}<br>console.log(sum(2, 3)); // 5<br>&lt;/pre&gt;</pre><h3>4. Embed Code in Websites</h3><p>For developers creating websites, embedding interactive code snippets improves engagement.</p><h4>Tools:</h4><ul><li><strong>CodePen</strong> (<a href="https://codepen.io/">https://codepen.io</a>): Share interactive front-end code.</li><li><strong>Replit</strong> (<a href="https://replit.com/">https://replit.com</a>): Share runnable code snippets.</li><li><strong>JSFiddle</strong> (<a href="https://jsfiddle.net/">https://jsfiddle.net</a>): Create and test HTML, CSS, and JavaScript snippets.</li></ul><h3>5. Use Screenshots or Images for Static Snippets</h3><p>If sharing code on social media or presentations:</p><ul><li>Use tools like <strong>Carbon</strong>, <strong>CodeSnap</strong> (VS Code extension), or <strong>Snappify</strong> (<a href="https://snappify.io/">https://snappify.io</a>) to create aesthetically pleasing code images.</li><li>Add your name, logo, or watermark for branding.</li></ul><h3>6. Formatting Guidelines</h3><p>Follow these best practices to improve readability:</p><ul><li><strong>Indentation</strong>: Use consistent spaces or tabs (e.g., 2 or 4 spaces).</li><li><strong>Commenting</strong>: Add comments to clarify complex parts.</li><li><strong>Whitespace</strong>: Add enough spacing to separate logical blocks.</li><li><strong>Font Style</strong>: Use monospaced fonts like Courier New, Fira Code, or Consolas.</li></ul><p>Example Styled Code Snippet:</p><h4>Markdown Example (JavaScript):</h4><pre>// Function to calculate factorial<br>function factorial(n) {<br>    if (n === 0 || n === 1) {<br>        return 1;<br>    }<br>    return n * factorial(n - 1);<br>}<br><br>console.log(factorial(5)); // Output: 120</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86b6d3ab8be8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Interview Questions 2025]]></title>
            <link>https://mdforhadsarker.medium.com/javascript-interview-questions-2025-b6f23bc75f17?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6f23bc75f17</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[interview-question-answer]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[frontend-developer]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Sat, 04 Jan 2025 15:04:56 GMT</pubDate>
            <atom:updated>2025-01-04T15:04:56.342Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>1. What is the difference between var, let, and const in JavaScript?</strong></p><ul><li>var: Function-scoped, can be re-declared, hoisted.</li><li>let: Block-scoped, cannot be re-declared, not hoisted.</li><li>const: Block-scoped, cannot be re-assigned.</li></ul><p>Example:</p><pre>var x = 10;<br>let y = 20;<br>const z = 30;<br><br>x = 15; // Allowed<br>y = 25; // Allowed<br>z = 35; // Error: Assignment to constant variable</pre><p><strong>2. Explain the concept of closures in JavaScript with an example.</strong></p><ul><li>Closures occur when a function retains access to its lexical scope, even when executed outside of it.</li><li>Example:</li></ul><pre>function outer() {<br>  let count = 0;<br>  return function inner() {<br>    count++;<br>    return count;<br>  };<br>}<br>const counter = outer();<br>console.log(counter()); // 1<br>console.log(counter()); // 2</pre><p><strong>3. How does the this keyword work in JavaScript?</strong></p><ul><li>Refers to the object calling the function.</li><li>Context changes based on how the function is invoked.</li><li>Example:</li></ul><pre>const obj = {<br>  name: &#39;Forhad&#39;,<br>  getName: function () {<br>    return this.name;<br>  }<br>};<br>console.log(obj.getName()); // &quot;Forhad&quot;</pre><p><strong>4. What are higher-order functions, and can you provide an example?</strong></p><ul><li>Functions that take other functions as arguments or return functions.</li><li>Example:</li></ul><pre>const numbers = [1, 2, 3, 4];<br>const squared = numbers.map(num =&gt; num * num);<br>console.log(squared); // [1, 4, 9, 16]</pre><p><strong>5. What is the difference between synchronous and asynchronous JavaScript?</strong></p><ul><li>Synchronous: Executes code sequentially.</li><li>Asynchronous: Allows non-blocking execution using callbacks, promises, or async/await.</li><li>Example:</li></ul><pre>console.log(&#39;Start&#39;);<br>setTimeout(() =&gt; console.log(&#39;Async operation&#39;), 1000);<br>console.log(&#39;End&#39;);</pre><p><strong>6. Explain the difference between forEach and map methods in arrays.</strong></p><ul><li>forEach: Iterates over elements, does not return a new array.</li><li>map: Creates a new array with the results of a callback function.</li><li>Example:</li></ul><pre>const arr = [1, 2, 3];<br>arr.forEach(num =&gt; console.log(num * 2)); // Logs: 2, 4, 6<br>const doubled = arr.map(num =&gt; num * 2);<br>console.log(doubled); // [2, 4, 6]</pre><p><strong>7. What is the purpose of promises, and how do you use them?</strong></p><ul><li>Promises handle asynchronous operations and avoid callback hell.</li><li>Example:</li></ul><pre>const promise = new Promise((resolve, reject) =&gt; {<br>  const success = true;<br>  if (success) resolve(&#39;Success&#39;);<br>  else reject(&#39;Error&#39;);<br>});<br><br>promise.then(console.log).catch(console.error);</pre><p><strong>8. What are arrow functions, and how do they differ from regular functions?</strong></p><ul><li>Shorter syntax, do not have their own this.</li><li>Example:</li></ul><pre>const add = (a, b) =&gt; a + b;<br>console.log(add(5, 3)); // 8</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6f23bc75f17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML & CSS Interview Questions and Answers 2025 for 2–5 Years Experiences]]></title>
            <link>https://mdforhadsarker.medium.com/html-css-interview-questions-and-answers-2025-for-2-5-years-experiences-09680ac38e35?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/09680ac38e35</guid>
            <category><![CDATA[questions]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[answers]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Sat, 04 Jan 2025 12:43:14 GMT</pubDate>
            <atom:updated>2025-01-04T12:43:14.073Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. What is the difference between em and rem units in CSS?</h3><p><strong>Answer:</strong></p><ul><li>em: Relative to the font size of the parent element. For example, if the parent font size is 16px and you set font-size: 2em;, the font size will be 32px.</li><li>rem: Relative to the root element (&lt;html&gt;). If the root font size is 16px, font-size: 2rem; will always be 32px, regardless of the parent element’s font size.</li></ul><p><strong>Explanation:</strong><br>em is context-sensitive, which can lead to cascading size changes, while rem ensures consistency and is easier to maintain in large projects.</p><pre>html { font-size: 16px; }<br>.parent { font-size: 20px; }<br>.child { font-size: 2em; } /* 40px because it inherits from parent */<br>.child-rem { font-size: 2rem; } /* 32px because it inherits from root */</pre><h3>2. Explain the purpose of the &lt;meta viewport&gt; tag in responsive design.</h3><p><strong>Answer:</strong><br>The &lt;meta viewport&gt; tag ensures a web page is rendered properly on different devices by controlling the viewport&#39;s size and scaling.</p><p>Example:</p><pre>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;</pre><ul><li>width=device-width: Sets the viewport width to the device&#39;s screen width.</li><li>initial-scale=1: Ensures a 1:1 scaling ratio.</li></ul><p><strong>Explanation:</strong><br>Without this tag, websites might appear zoomed out or incorrectly scaled on mobile devices.</p><h3>3. How would you implement a responsive navigation bar using CSS?</h3><p><strong>Answer:</strong></p><ol><li>Use a <strong>flexbox layout</strong> for the navigation items.</li><li>Add a <strong>media query</strong> to switch the layout for smaller screens.</li><li>Include a <strong>hamburger menu</strong> for mobile.</li></ol><p>Example:</p><pre>&lt;nav&gt;<br>  &lt;ul class=&quot;nav&quot;&gt;<br>    &lt;li&gt;Home&lt;/li&gt;<br>    &lt;li&gt;About&lt;/li&gt;<br>    &lt;li&gt;Contact&lt;/li&gt;<br>  &lt;/ul&gt;<br>&lt;/nav&gt;<br>&lt;style&gt;<br>  .nav {<br>    display: flex;<br>    justify-content: space-around;<br>  }<br>  @media (max-width: 600px) {<br>    .nav {<br>      flex-direction: column;<br>    }<br>  }<br>&lt;/style&gt;</pre><p><strong>Explanation:</strong><br>Flexbox and media queries ensure the navigation adapts to different screen sizes.</p><h3>4. What are pseudo-elements in CSS? Can you give examples?</h3><p><strong>Answer:</strong><br>Pseudo-elements allow you to style specific parts of an element without adding extra HTML.</p><p>Examples:</p><ul><li>::before – Adds content before an element.</li><li>::after – Adds content after an element.</li><li>::placeholder – Styles placeholder text in input fields.</li></ul><p>Example:</p><pre>h1::before {<br>  content: &quot;★ &quot;;<br>  color: gold;<br>}</pre><p><strong>Explanation:</strong><br>They are often used for decorative purposes, like adding icons or styling specific text parts.</p><h3>5. Explain the CSS Box Model and its components.</h3><p><strong>Answer:</strong><br>The CSS Box Model determines how elements are sized and spaced on a web page. It consists of:</p><ol><li><strong>Content</strong>: The area where text or images are displayed.</li><li><strong>Padding</strong>: Space between the content and the border.</li><li><strong>Border</strong>: Surrounds the padding and content.</li><li><strong>Margin</strong>: Space between the element and neighboring elements.</li></ol><p>Example:</p><pre>div {<br>  width: 100px; /* content */<br>  padding: 10px; /* space inside border */<br>  border: 5px solid black; /* border thickness */<br>  margin: 20px; /* space outside border */<br>}</pre><p><strong>Explanation:</strong><br>Understanding the box model is crucial for layout design and spacing.</p><p><strong>6. What is the difference between inline, inline-block, and block elements in HTML?</strong></p><ul><li>inline: Does not start on a new line, only takes up necessary width.</li><li>inline-block: Similar to inline but allows setting width and height.</li><li>block: Starts on a new line, takes full width.</li></ul><pre>&lt;span style=&quot;display: inline;&quot;&gt;Inline&lt;/span&gt;<br>&lt;div style=&quot;display: block;&quot;&gt;Block&lt;/div&gt;<br>&lt;span style=&quot;display: inline-block; width: 100px;&quot;&gt;Inline-Block&lt;/span&gt;</pre><p><strong>7. What are media queries, and how would you use them in a project?</strong></p><ul><li>Media queries apply styles based on device properties like width or orientation.</li><li>Example:</li></ul><pre>@media (max-width: 600px) {<br>  body {<br>    background-color: lightblue;<br>  }<br>}</pre><p><strong>8. What is the difference between relative, absolute, fixed, and sticky positioning in CSS?</strong></p><ul><li>relative: Positioned relative to its normal position.</li><li>absolute: Positioned relative to the nearest positioned ancestor.</li><li>fixed: Positioned relative to the viewport.</li><li>sticky: Toggles between relative and fixed based on scroll.</li></ul><pre>&lt;div style=&quot;position: relative; top: 10px;&quot;&gt;Relative&lt;/div&gt;<br>&lt;div style=&quot;position: absolute; top: 20px;&quot;&gt;Absolute&lt;/div&gt;<br>&lt;div style=&quot;position: fixed; top: 30px;&quot;&gt;Fixed&lt;/div&gt;<br>&lt;div style=&quot;position: sticky; top: 40px;&quot;&gt;Sticky&lt;/div&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=09680ac38e35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Most Important JavaScript Questions]]></title>
            <link>https://mdforhadsarker.medium.com/most-important-jabascript-questions-5b61e8b2f9b9?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b61e8b2f9b9</guid>
            <category><![CDATA[questions]]></category>
            <category><![CDATA[important-interview]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Mon, 25 Nov 2024 08:14:10 GMT</pubDate>
            <atom:updated>2025-01-04T15:09:33.423Z</atom:updated>
            <content:encoded><![CDATA[<p>𝘠𝘰𝘶 𝘯𝘦𝘦𝘥 𝘵𝘰 𝘮𝘢𝘴𝘵𝘦𝘳 𝘵𝘩𝘦𝘴𝘦 𝘧𝘳𝘦𝘲𝘶𝘦𝘯𝘵𝘭𝘺 𝘢𝘴𝘬𝘦𝘥 𝘫𝘢𝘷𝘢𝘴𝘤𝘳𝘪𝘱𝘵 𝘲𝘶𝘦𝘴𝘵𝘪𝘰𝘯𝘴 before your next interview</p><p>🔸 Implement the compose() and pipe() polyfill<br>🔸 Promises (Polyfill for Promise.all, Promise.race, Promise.allSettled)<br>🔸 Implement the map, filter, reduce, and forEach polyfills<br>🔸 Implement the Function.bind, call, and apply methods on the Function prototype<br>🔸 Implement Async.parallel and Async.series for executing async tasks<br>🔸 Build a Promise from scratch<br>🔸 Implement a Retry API<br>🔸 Implement Memoization<br>🔸 Currying (with examples)<br>🔸 String.prototype.repeat<br>🔸 Design patterns (Singleton, Factory patterns, Builder etc.)<br>🔸 Implement the Publisher-Subscriber pattern in JavaScript<br>🔸 Prototype and prototype inheritance<br>🔸 How rendering works in the browser<br>🔸 Event delegation and event propagation in JavaScript<br>🔸 Progressive Web Applications (PWAs)<br>🔸 Clone an object<br>🔸 Debouncing and Throttling<br>🔸 Implement clearAllTimeout()<br>🔸 How does “this” work in different scenarios?<br>🔸 What is the difference between synchronous and asynchronous code?<br>🔸 Explain the concept of “truthy” and “falsy” values.<br>🔸 What are template literals in ES6?<br>🔸 How do you handle errors in JavaScript?<br>🔸 Implement a function to flatten a nested array<br>🔸 Implement an LRU Cache<br>🔸 What are closures in JavaScript?<br>🔸 Explain the event loop in JavaScript.<br>🔸 What is the difference between ‘var’, ‘let’, and ‘const’?<br>🔸 How does hoisting work in JavaScript?<br>🔸 What is the purpose of ‘setTimeout’ and ‘setInterval’?<br>🔸 Explain how to use the Fetch API.<br>🔸 What is a service worker in the context of PWAs?<br>🔸 Describe how to implement deep cloning of an object.<br>🔸 What are modules in JavaScript? How do you use them?<br>🔸 Explain the concept of `this` binding with examples.<br>🔸 What is a closure? Provide an example.<br>🔸 How do you prevent default behavior of an event?<br>🔸 What are arrow functions, and how do they differ from regular functions?<br>🔸 Explain the concept of promises chaining.<br>🔸 What is the purpose of ‘Object.create()’?<br>🔸 How can you check if an object is an array?<br>🔸 What are IIFE (Immediately Invoked Function Expressions)?<br>🔸 Explain how to create a custom event in JavaScript.<br>🔸 What is JSON, and how do you parse it?<br>🔸 Describe how to implement a simple event emitter.<br>🔸 What are weak references in JavaScript?<br>🔸 How do you optimize performance in large-scale applications?<br>🔸 Explain how to use localStorage and sessionStorage.<br>🔸 What are some common security issues in JavaScript applications?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b61e8b2f9b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Simple Calculator Using JavaScript , Html and CSS]]></title>
            <link>https://mdforhadsarker.medium.com/create-simple-calculator-using-javascript-html-and-css-727b452aa029?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/727b452aa029</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[simple-calculator]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[calculator-code]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Sat, 07 Sep 2024 10:56:10 GMT</pubDate>
            <atom:updated>2024-09-07T10:56:10.374Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create Simple Calculator Using JavaScript , Html and CSS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*MQUL1vslZJDhZ8wdjsv2XA.png" /><figcaption>Calculator</figcaption></figure><p>First you need to create a folder and You have to create three files , index.html , index.js and index.css .</p><p>First lets talk about index.js</p><h3>calculate() Function:</h3><ol><li><strong>Retrieve values from input fields and dropdown</strong>:</li></ol><pre>const num1 = document.getElementById(&quot;num1&quot;).value;<br>const num2 = document.getElementById(&quot;num2&quot;).value;<br>const operatorType = document.getElementById(&quot;operator&quot;).value;</pre><ul><li>This retrieves the values from the input fields for the first number (num1), the second number (num2), and the selected operator (operatorType).</li><li>document.getElementById(&quot;num1&quot;).value gets the value of the input field with the ID num1. Similarly, it does for num2 and operator.</li></ul><p><strong>2. Define a </strong><strong>result variable</strong>:</p><pre>let result;</pre><p>This variable will store the final calculated value based on the operator.</p><p><strong>3. Switch statement to perform calculations</strong>:</p><pre>switch (operatorType) {<br>  case &quot;+&quot;:<br>    result = Number(num1) + Number(num2);<br>    break;<br>  case &quot;-&quot;:<br>    result = Number(num1) - Number(num2);<br>    break;<br>  case &quot;*&quot;:<br>    result = Number(num1) * Number(num2);<br>    break;<br>  case &quot;/&quot;:<br>    if (Number(num1) === 0) {<br>      result = &quot;Error! Division by zero&quot;;<br>    } else {<br>      result = Number(num1) / Number(num2);<br>    }<br>    break;<br>  default:<br>    result = &quot;Invalid operator&quot;;<br>}</pre><ul><li>Based on the value of operatorType, the switch statement performs different mathematical operations.</li><li>It uses the Number() function to convert the input values (num1 and num2) from strings to numbers.</li><li>Each case corresponds to one of the operations (+, -, *, /).</li><li>For division (/), there’s an additional check for division by zero (num1 === 0). If the first number is zero, it displays an error message. Otherwise, it divides num1 by num2.</li></ul><p><strong>4. Display the result</strong>:</p><pre>document.getElementById(&quot;result&quot;).innerText = &quot;Result: &quot; + result.toFixed(2);</pre><ul><li>The result is displayed in the HTML element with the ID result. It updates the innerText of this element.</li><li>toFixed(2) is used to format the result to 2 decimal places, ensuring a more user-friendly output for floating-point numbers.</li></ul><p>Now let’s talk about resetFields() Function:</p><ol><li><strong>Clear input fields and reset operator</strong>:</li></ol><pre>document.getElementById(&quot;num1&quot;).value = &quot;&quot;;<br>document.getElementById(&quot;num2&quot;).value = &quot;&quot;;<br>document.getElementById(&quot;operator&quot;).value = &quot;+&quot;;</pre><p>This function resets the values of the num1, num2, and operator fields back to their default states. num1 and num2 are set to empty strings, and the operator is reset to +.</p><p><strong>2. Clear the result display</strong>:</p><pre>document.getElementById(&quot;result&quot;).innerText = &quot;Result: &quot;;</pre><p>This clears the result section by setting the text back to “Result: “, removing any previous calculations.</p><p>The whole index.js</p><pre>function calculate() {<br>  const num1 = document.getElementById(&quot;num1&quot;).value;<br>  const num2 = document.getElementById(&quot;num2&quot;).value;<br>  const operatorType = document.getElementById(&quot;operator&quot;).value;<br><br>  let result;<br><br>  switch (operatorType) {<br>    case &quot;+&quot;:<br>      result = Number(num1) + Number(num2);<br>      break;<br>    case &quot;-&quot;:<br>      result = Number(num1) - Number(num2);<br>      break;<br>    case &quot;*&quot;:<br>      result = Number(num1) * Number(num2);<br>      break;<br>    case &quot;/&quot;:<br>      if (Number(num1) === 0) {<br>        result = &quot;Error! Division by zeror&quot;;<br>      } else {<br>        result = Number(num1) / Number(num2);<br>      }<br>      break;<br>    default:<br>      result = &quot;Invalid operator&quot;;<br>  }<br><br>  document.getElementById(&quot;result&quot;).innerText = &quot;Result: &quot; + result.toFixed(2);<br>}<br><br>function resetFields() {<br>  document.getElementById(&quot;num1&quot;).value = &quot;&quot;;<br>  document.getElementById(&quot;num2&quot;).value = &quot;&quot;;<br>  document.getElementById(&quot;operator&quot;).value = &quot;+&quot;;<br>  document.getElementById(&quot;result&quot;).innerText = &quot;Result: &quot;;<br>}</pre><h3>Summary:</h3><ul><li><strong>calculate()</strong> performs the actual calculation based on user inputs and displays the result.</li><li><strong>resetFields()</strong> clears the input fields and resets the displayed result to its default state.</li></ul><p>This code provides the functionality for a simple calculator, handling basic operations like addition, subtraction, multiplication, and division, with error handling for division by zero.</p><p>Now let’s talk about index.html now</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;<br>    &lt;title&gt;Calculator&lt;/title&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;index.css&quot; /&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;div class=&quot;wrapper&quot;&gt;<br>      &lt;h1&gt;Simple Calculator&lt;/h1&gt;<br><br>      &lt;div class=&quot;input-group&quot;&gt;<br>        &lt;label for=&quot;num1&quot;&gt;Enter first number:&lt;/label&gt;<br>        &lt;input type=&quot;number&quot; id=&quot;num1&quot; /&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;input-group&quot;&gt;<br>        &lt;label for=&quot;num2&quot;&gt;Enter second number:&lt;/label&gt;<br>        &lt;input type=&quot;number&quot; id=&quot;num2&quot; /&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;input-group&quot;&gt;<br>        &lt;label for=&quot;operator&quot;&gt;Choose an operator:&lt;/label&gt;<br>        &lt;select id=&quot;operator&quot;&gt;<br>          &lt;option value=&quot;+&quot;&gt;+&lt;/option&gt;<br>          &lt;option value=&quot;-&quot;&gt;-&lt;/option&gt;<br>          &lt;option value=&quot;*&quot;&gt;*&lt;/option&gt;<br>          &lt;option value=&quot;/&quot;&gt;/&lt;/option&gt;<br>        &lt;/select&gt;<br>      &lt;/div&gt;<br><br>      &lt;div class=&quot;button-group&quot;&gt;<br>        &lt;button onclick=&quot;calculate()&quot;&gt;Calculate&lt;/button&gt;<br>        &lt;button onclick=&quot;resetFields()&quot;&gt;Reset&lt;/button&gt;<br>      &lt;/div&gt;<br><br>      &lt;h3 id=&quot;result&quot;&gt;Result:&lt;/h3&gt;<br>    &lt;/div&gt;<br><br>    &lt;script src=&quot;index.js&quot;&gt;&lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>This is very basic html code I used . You may easily understand .</p><p>This HTML file defines a simple calculator interface within a structured layout. Here’s a summary:</p><p><strong>Document Structure</strong>:</p><ul><li>The page is wrapped in a div with the class &quot;wrapper&quot; for styling and layout purposes.</li><li>The &lt;h1&gt; heading displays &quot;Simple Calculator.&quot;</li></ul><p><strong>Input Fields</strong>:</p><ul><li>There are two input fields (&lt;input type=&quot;number&quot;&gt;) for entering the first and second numbers, each inside a div with the class &quot;input-group&quot;, which provides structure for labels and inputs.</li><li>A dropdown (&lt;select&gt;) allows users to choose an operator (+, -, *, /).</li></ul><p><strong>Buttons</strong>:</p><ul><li>Two buttons are provided inside a div with the class &quot;button-group&quot;:</li><li><strong>Calculate</strong> button triggers the calculate() function to perform the operation.</li><li><strong>Reset</strong> button triggers the resetFields() function to clear the inputs and result.</li></ul><p><strong>Result Display</strong>:</p><ul><li>A &lt;h3&gt; tag with the ID result is used to display the calculation result dynamically.</li></ul><p><strong>Result Display</strong>:</p><ul><li>A &lt;h3&gt; tag with the ID result is used to display the calculation result dynamically.</li></ul><p>This code provides a clean and structured layout for a basic calculator using HTML, CSS (linked as index.css), and JavaScript.</p><p>Here is the index.css</p><pre><br>/* Style the body */<br>body {<br>  font-family: Arial, sans-serif;<br>  background-color: #f0f0f0;<br>  margin: 0;<br>  padding: 20px;<br>  display: flex;<br>  justify-content: center;<br>  align-items: center;<br>  height: 100vh;<br>}<br><br>/* Style the wrapper */<br>.wrapper {<br>  background-color: #fff;<br>  padding: 30px;<br>  border-radius: 10px;<br>  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);<br>  max-width: 400px;<br>  width: 100%;<br>  text-align: center;<br>}<br><br>/* Style the heading */<br>h1 {<br>  color: #333;<br>  margin-bottom: 20px;<br>}<br><br>/* Style the input groups */<br>.input-group {<br>  margin-bottom: 15px;<br>  align-items: flex-start;<br>  text-align: left;<br>}<br><br>label {<br>  display: block;<br>  margin-bottom: 5px;<br>  font-weight: bold;<br>}<br><br>input[type=&quot;number&quot;],<br>select {<br>  padding: 10px;<br>  font-size: 16px;<br>  width: 100%;<br>  border-radius: 5px;<br>  border: 1px solid #ccc;<br>  box-sizing: border-box;<br>}<br><br>/* Style the button group */<br>.button-group {<br>  margin-top: 20px;<br>}<br><br>button {<br>  padding: 10px 20px;<br>  margin: 5px;<br>  font-size: 16px;<br>  border: none;<br>  border-radius: 5px;<br>  background-color: #4caf50;<br>  color: white;<br>  cursor: pointer;<br>}<br><br>button:hover {<br>  background-color: #45a049;<br>}<br><br>/* Style the result display */<br>h3 {<br>  margin-top: 20px;<br>  color: #333;<br>  font-size: 24px;<br>}</pre><p>I hope you have enjoyed to read this post . Please like ,share, and subscribe if you like the post .</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=727b452aa029" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[40 JavaScript questions and Answer for you to prepare JavaScript Developer]]></title>
            <link>https://mdforhadsarker.medium.com/40-javascript-questions-and-answer-for-you-to-prepare-javascript-developer-e68e57d6133a?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/e68e57d6133a</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[top-40-questions]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Sat, 07 Sep 2024 05:41:20 GMT</pubDate>
            <atom:updated>2024-09-07T05:41:20.089Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*5WSGHeCDroH_mr_C" /><figcaption>javaScript interview question</figcaption></figure><ol><li><strong>What is JavaScript?</strong> JavaScript is a programming language primarily used for creating interactive and dynamic web pages. It can manipulate web elements, respond to user input, and handle server communications.</li></ol><pre>alert(&quot;Hello, World!&quot;);</pre><p><strong>2. What are the data types supported by JavaScript?</strong></p><ul><li><strong>Primitive types</strong>: Number, String, Boolean, Null, Undefined, Symbol, BigInt</li><li><strong>Non-primitive types</strong>: Object (includes arrays, functions, etc.)</li></ul><pre>let num = 42; // Number<br>let str = &quot;Hello&quot;; // String<br>let obj = { name: &quot;John&quot; }; // Object</pre><p><strong>What is the difference between </strong><strong>let, </strong><strong>const, and </strong><strong>var?</strong></p><ul><li>var: function-scoped, can be re-declared and updated.</li><li>let: block-scoped, can be updated but not re-declared in the same scope.</li><li>const: block-scoped, cannot be updated or re-declared.</li></ul><pre>var x = 1; <br>let y = 2;<br>const z = 3;</pre><p><strong>Explain how </strong><strong>== and </strong><strong>=== differ.</strong></p><ul><li>==: checks equality with type coercion (converts types if necessary).</li><li>===: checks strict equality (no type conversion).</li></ul><pre>5 == &quot;5&quot;;  // true (type coercion)<br>5 === &quot;5&quot;; // false (no type coercion)</pre><p><strong>What is a closure?</strong> A closure is a function that retains access to variables from its outer function even after the outer function has finished executing.</p><p>Example:</p><pre>function outer() {<br>  let count = 0;<br>  return function inner() {<br>    count++;<br>    return count;<br>  };<br>}<br>const counter = outer();<br>console.log(counter()); // 1<br>console.log(counter()); // 2</pre><p><strong>What is hoisting?</strong> Hoisting is the default behavior of moving variable and function declarations to the top of their scope during compilation.</p><p>Example:</p><pre>console.log(a); // undefined (hoisted)<br>var a = 5;</pre><p><strong>Explain the concept of “this” in JavaScript.</strong> this refers to the object that is executing the current function. It changes depending on how a function is called.</p><p>Example:</p><pre>const obj = {<br>  name: &quot;Alice&quot;,<br>  getName: function() {<br>    return this.name;<br>  }<br>};<br>console.log(obj.getName()); // Alice</pre><p><strong>What are JavaScript prototypes?</strong> JavaScript prototypes are a mechanism by which objects inherit properties and methods from another object.</p><pre>function Person(name) {<br>  this.name = name;<br>}<br>Person.prototype.sayHello = function() {<br>  console.log(&quot;Hello, &quot; + this.name);<br>};<br>const person1 = new Person(&quot;John&quot;);<br>person1.sayHello(); // Hello, John</pre><p><strong>What is the difference between </strong><strong>null and </strong><strong>undefined?</strong></p><ul><li>null: explicitly represents the absence of a value.</li><li>undefined: indicates a variable that has been declared but not initialized.</li></ul><p>Example:</p><pre>let a;<br>let b = null;<br>console.log(a); // undefined<br>console.log(b); // null</pre><p><strong>How does JavaScript handle asynchronous operations?</strong> JavaScript handles asynchronous operations using callbacks, promises, and async/await.</p><p>Example:</p><pre>setTimeout(() =&gt; console.log(&quot;Asynchronous&quot;), 1000);</pre><p><strong>What is a promise?</strong> A promise is an object representing the eventual completion (or failure) of an asynchronous operation and its resulting value.</p><p>Example:</p><pre>const promise = new Promise((resolve, reject) =&gt; {<br>  setTimeout(() =&gt; resolve(&quot;Success!&quot;), 1000);<br>});<br>promise.then(result =&gt; console.log(result)); // Success!</pre><p><strong>What are async/await functions?</strong> async/await is a syntactic sugar over promises that allows you to write asynchronous code in a synchronous style.</p><p>Example:</p><pre>async function fetchData() {<br>  let response = await fetch(&quot;https://api.example.com&quot;);<br>  let data = await response.json();<br>  console.log(data);<br>}<br>fetchData();</pre><p><strong>Explain event delegation in JavaScript.</strong> Event delegation is the process of attaching a single event listener to a parent element to handle events on its child elements, leveraging event bubbling.</p><p>Example:</p><pre>document.getElementById(&quot;parent&quot;).addEventListener(&quot;click&quot;, (event) =&gt; {<br>  if (event.target.matches(&quot;button&quot;)) {<br>    console.log(&quot;Button clicked&quot;);<br>  }<br>});</pre><p><strong>What are JavaScript modules?</strong> JavaScript modules are reusable pieces of code that can be exported from one file and imported into another.</p><p>Example:</p><pre>// math.js<br>export const add = (a, b) =&gt; a + b;<br><br>// app.js<br>import { add } from &#39;./math.js&#39;;<br>console.log(add(2, 3)); // 5</pre><p><strong>How can you prevent a function from being called multiple times?</strong> Use a debounce function or a flag to prevent multiple calls.</p><p>Example (Debounce):</p><pre>function debounce(fn, delay) {<br>  let timeout;<br>  return function() {<br>    clearTimeout(timeout);<br>    timeout = setTimeout(fn, delay);<br>  };<br>}</pre><p><strong>What is the event loop?</strong> The event loop is responsible for handling asynchronous callbacks in JavaScript. It checks the call stack and the message queue, executing callbacks when the call stack is empty.</p><pre>console.log(&quot;Start&quot;);<br>setTimeout(() =&gt; console.log(&quot;Async Task&quot;), 0);<br>console.log(&quot;End&quot;);<br>// Output: Start, End, Async Task</pre><p><strong>What is the difference between </strong><strong>apply() and </strong><strong>call() methods?</strong> Both are used to call a function with a given this context, but apply() takes arguments as an array, while call() takes arguments separately.</p><p>Example:</p><pre>function greet(greeting, name) {<br>  console.log(greeting + &quot;, &quot; + name);<br>}<br>greet.call(null, &quot;Hello&quot;, &quot;Alice&quot;); // Hello, Alice<br>greet.apply(null, [&quot;Hello&quot;, &quot;Bob&quot;]); // Hello, Bob</pre><p><strong>What is </strong><strong>bind() method used for?</strong> bind() creates a new function that, when called, has its this context set to a provided value.</p><p>Example:</p><pre>const person = {<br>  name: &quot;John&quot;,<br>  greet: function() {<br>    console.log(&quot;Hello, &quot; + this.name);<br>  }<br>};<br>const greet = person.greet.bind({ name: &quot;Alice&quot; });<br>greet(); // Hello, Alice</pre><p><strong>What is a JavaScript event loop?</strong> The event loop is the mechanism that allows JavaScript to perform non-blocking I/O operations, even though JavaScript is single-threaded.</p><p><strong>Explain the concept of “event bubbling” and “event capturing”.</strong></p><ul><li><strong>Event bubbling</strong>: events propagate from the innermost target element up through the DOM tree.</li><li><strong>Event capturing</strong>: events are handled from the outermost element to the innermost.</li></ul><p>Example:</p><pre>document.getElementById(&quot;child&quot;).addEventListener(&quot;click&quot;, () =&gt; console.log(&quot;Child clicked&quot;), false); // Bubbling<br>document.getElementById(&quot;parent&quot;).addEventListener(&quot;click&quot;, () =&gt; console.log(&quot;Parent clicked&quot;), true); // Capturing</pre><p><strong>What is the difference between </strong><strong>deep copy and </strong><strong>shallow copy?</strong></p><ul><li><strong>Shallow copy</strong>: copies only the immediate properties (nested objects are referenced).</li><li><strong>Deep copy</strong>: copies all levels of an object.</li></ul><p>Example (Shallow Copy):</p><pre>let obj = { a: 1, b: { c: 2 } };<br>let shallowCopy = { ...obj };<br>shallowCopy.b.c = 3;<br>console.log(obj.b.c); // 3 (nested object is shared)</pre><p><strong>What are generator functions?</strong> Generator functions allow you to yield multiple values over time using the yield keyword. They can be paused and resumed.</p><p>Example:</p><pre>function* generator() {<br>  yield 1;<br>  yield 2;<br>  yield 3;<br>}<br>const gen = generator();<br>console.log(gen.next().value); // 1<br>console.log(gen.next().value); // 2</pre><p><strong>What is the </strong><strong>new keyword used for?</strong> The new keyword is used to create instances of a user-defined object type or a constructor function.</p><p>Example:</p><pre>function Person(name) {<br>  this.name = name;<br>}<br>const person = new Person(&quot;John&quot;);<br>console.log(person.name); // John</pre><h3>How do JavaScript’s setTimeout and setInterval work?</h3><ul><li><strong>setTimeout()</strong>: Executes a function once after a specified delay (in milliseconds).</li><li><strong>setInterval()</strong>: Executes a function repeatedly at specified intervals (in milliseconds).</li></ul><pre>// setTimeout<br>setTimeout(() =&gt; console.log(&quot;This runs after 2 seconds&quot;), 2000);<br><br>// setInterval<br>setInterval(() =&gt; console.log(&quot;This runs every 1 second&quot;), 1000);</pre><h3>What is a WeakMap and how is it different from a Map?</h3><ul><li><strong>Map</strong>: Holds key-value pairs where the keys can be any data type, and it maintains references to the objects.</li><li><strong>WeakMap</strong>: Only accepts objects as keys and does not prevent garbage collection if the key object is no longer referenced elsewhere. The key-value pairs in a WeakMap are not enumerable.</li></ul><pre>let map = new Map();<br>let weakMap = new WeakMap();<br><br>let obj = { name: &quot;John&quot; };<br>map.set(obj, &quot;Value&quot;);<br>weakMap.set(obj, &quot;Value&quot;);<br><br>obj = null; // obj is eligible for garbage collection in WeakMap but not in Map</pre><h3>26. What is a Set in JavaScript?</h3><p>A <strong>Set</strong> is a collection of unique values. It does not allow duplicate values and provides methods like add(), delete(), and has().</p><pre>let set = new Set();<br>set.add(1);<br>set.add(2);<br>set.add(1); // Duplicate values are ignored<br>console.log(set); // Set { 1, 2 }</pre><h3>27. What is Object.create() used for?</h3><p>Object.create() is used to create a new object with a specified prototype and properties. It allows you to set the prototype of the new object.</p><pre>const proto = { greet() { return &quot;Hello&quot;; } };<br>const obj = Object.create(proto);<br>console.log(obj.greet()); // Hello</pre><h3>28. How does JavaScript’s garbage collection work?</h3><p>JavaScript’s garbage collection uses an algorithm called <strong>mark-and-sweep</strong>. It identifies objects that are still reachable and marks them as “in use.” Objects that are unreachable are automatically deleted, freeing up memory.</p><h3>29. What are “decorators” in JavaScript?</h3><p>Decorators are a proposal for JavaScript that provide a way to modify classes and their properties in a declarative way. They are not yet part of the standard, but are used in frameworks like Angular.</p><pre>function log(target) {<br>  console.log(`${target.name} was created`);<br>}<br><br>@log<br>class MyClass {<br>  constructor() {<br>    this.name = &quot;Decorated Class&quot;;<br>  }<br>}<br>// Logs: &quot;MyClass was created&quot;</pre><h3>30. Explain the difference between prototype and __proto__.</h3><ul><li><strong>prototype</strong>: A property of constructor functions used to define methods and properties that are shared among all instances.</li><li><strong>__proto__</strong>: An object property that points to the prototype of an object.</li></ul><pre>function Person() {}<br>Person.prototype.greet = function() { console.log(&quot;Hello&quot;); };<br><br>let person = new Person();<br>person.__proto__ === Person.prototype; // true</pre><h3>31. What is the purpose of Object.assign()?</h3><p>Object.assign() is used to copy the values of all enumerable properties from one or more source objects to a target object.</p><pre>let target = { a: 1 };<br>let source = { b: 2, c: 3 };<br>Object.assign(target, source);<br>console.log(target); // { a: 1, b: 2, c: 3 }</pre><h3>32. What are “template literals”?</h3><p>Template literals allow embedded expressions and multiline strings using backticks (`). They also support placeholders using ${}.</p><pre>let name = &quot;John&quot;;<br>let greeting = `Hello, ${name}!`; // Embedded expression<br>console.log(greeting); // Hello, John!</pre><h3>33. What is the spread operator?</h3><p>The spread operator (...) expands an iterable (like an array) into individual elements. It can also be used to create shallow copies of arrays and objects.</p><pre>let arr = [1, 2, 3];<br>console.log(...arr); // 1 2 3<br><br>let obj = { a: 1 };<br>let newObj = { ...obj, b: 2 };<br>console.log(newObj); // { a: 1, b: 2 }</pre><h3>34. What is the rest parameter?</h3><p>The rest parameter (...) allows you to represent an indefinite number of arguments as an array in function definitions.</p><pre>function sum(...numbers) {<br>  return numbers.reduce((acc, num) =&gt; acc + num, 0);<br>}<br>console.log(sum(1, 2, 3)); // 6</pre><h3>35. Explain the for...of loop.</h3><p>The for...of loop is used to iterate over iterable objects (like arrays, strings, maps, sets) and returns the values of each element.</p><pre>let arr = [10, 20, 30];<br>for (let value of arr) {<br>  console.log(value); // 10, 20, 30<br>}</pre><h3>36. What are async and await keywords used for?</h3><p>The async and await keywords are used to work with promises in a more synchronous way. An async function returns a promise, and await is used to wait for the promise to resolve.</p><pre>async function fetchData() {<br>  let response = await fetch(&quot;https://api.example.com&quot;);<br>  let data = await response.json();<br>  console.log(data);<br>}<br>fetchData();</pre><h3>37. What is Symbol used for in JavaScript?</h3><p>Symbol is a unique and immutable data type used to create unique property keys, often used for object properties to avoid naming conflicts.</p><pre>const sym1 = Symbol(&quot;key&quot;);<br>const obj = { [sym1]: &quot;value&quot; };<br>console.log(obj[sym1]); // value</pre><h3>38. How do you create a class in JavaScript?</h3><p>You can create a class using the class keyword in ES6. A class can have a constructor, methods, and static methods.</p><pre>class Person {<br>  constructor(name) {<br>    this.name = name;<br>  }<br>  <br>  greet() {<br>    console.log(`Hello, ${this.name}`);<br>  }<br>}<br><br>let person = new Person(&quot;John&quot;);<br>person.greet(); // Hello, John</pre><h3>39. What is destructuring in JavaScript?</h3><p>Destructuring allows you to unpack values from arrays or properties from objects into distinct variables.</p><pre>let [a, b] = [1, 2];<br>console.log(a, b); // 1 2<br><br>let { name, age } = { name: &quot;Alice&quot;, age: 25 };<br>console.log(name, age); // Alice 25</pre><h3>40. What is the Proxy object?</h3><p>The Proxy object allows you to create a proxy for another object, which can intercept and redefine fundamental operations such as property access, assignment, and function invocation.</p><pre>let target = {};<br>let proxy = new Proxy(target, {<br>  get: function(obj, prop) {<br>    return prop in obj ? obj[prop] : &quot;Property does not exist&quot;;<br>  }<br>});<br>proxy.name = &quot;John&quot;;<br>console.log(proxy.name); // John<br>console.log(proxy.age);  // Property does not exist</pre><p>These answers provide a clear and concise explanation of common JavaScript concepts.</p><p>If you really like please like and share .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e68e57d6133a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jump into Git with these starter commands:]]></title>
            <link>https://mdforhadsarker.medium.com/jump-into-git-with-these-starter-commands-e43dcb567421?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/e43dcb567421</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[basic-git-commands]]></category>
            <category><![CDATA[git-commands]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-initial-command]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Sun, 24 Mar 2024 09:08:43 GMT</pubDate>
            <atom:updated>2024-03-24T09:08:43.679Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hfa5Yau-36unjA-Z7362JQ.png" /></figure><p>🌟 𝚐𝚒𝚝 𝚒𝚗𝚒𝚝: Kick things off with this command that creates a new Git repository right where you are.</p><p>🔄 𝚐𝚒𝚝 𝚌𝚕𝚘𝚗𝚎 &lt;𝚛𝚎𝚙𝚘&gt;: Want to get cracking on an existing project? This command copies it over to your local machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*MVIFaOrC-SepuwCL" /></figure><p>𝗠𝗮𝗸𝗶𝗻𝗴 𝗖𝗵𝗮𝗻𝗴𝗲𝘀</p><p>🔍 𝚐𝚒𝚝 𝚜𝚝𝚊𝚝𝚞𝚜: Take a quick peek at what’s changed with this command. It’s good practice to check in before and after you make changes.</p><p>➕ 𝚐𝚒𝚝 𝚊𝚍𝚍 &lt;𝚏𝚒𝚕𝚎𝚗𝚊𝚖𝚎&gt;: Made some tweaks? Stage them for a commit with this command that adds your files to the lineup.</p><p>📦 𝚐𝚒𝚝 𝚊𝚍𝚍 . or 𝚐𝚒𝚝 𝚊𝚍𝚍 -𝙰: Why add files one at a time when you can add all your changes in one fell swoop?</p><p>💾 𝚐𝚒𝚝 𝚌𝚘𝚖𝚖𝚒𝚝 -𝚖 “𝙲𝚘𝚖𝚖𝚒𝚝 𝚖𝚎𝚜𝚜𝚊𝚐𝚎”: Seal the deal on your changes with a commit and a handy message to remind you what you did.</p><p>𝗕𝗿𝗮𝗻𝗰𝗵𝗶𝗻𝗴 𝗢𝘂𝘁</p><p>📋 𝚐𝚒𝚝 𝚋𝚛𝚊𝚗𝚌𝚑: Curious about your branches? List them all out with this simple command.</p><p>🌱 𝚐𝚒𝚝 𝚋𝚛𝚊𝚗𝚌𝚑 &lt;𝚋𝚛𝚊𝚗𝚌𝚑𝚗𝚊𝚖𝚎&gt;: Grow your project with a new branch using this command.</p><p>🔄 𝚐𝚒𝚝 𝚌𝚑𝚎𝚌𝚔𝚘𝚞𝚝 &lt;𝚋𝚛𝚊𝚗𝚌𝚑𝚗𝚊𝚖𝚎&gt;: Jump over to another branch to keep working seamlessly.</p><p>🔗 𝚐𝚒𝚝 𝚖𝚎𝚛𝚐𝚎 &lt;𝚋𝚛𝚊𝚗𝚌𝚑𝚗𝚊𝚖𝚎&gt;: Done with changes on your side branch? Bring them back to the main branch with a merge.</p><p>𝗪𝗼𝗿𝗸𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗥𝗲𝗺𝗼𝘁𝗲𝘀</p><p>📤 𝚐𝚒𝚝 𝚙𝚞𝚜𝚑 𝚘𝚛𝚒𝚐𝚒𝚗 &lt;𝚋𝚛𝚊𝚗𝚌𝚑𝚗𝚊𝚖𝚎&gt;: Send your latest commits up to the cloud with this push command.</p><p>📥 𝚐𝚒𝚝 𝚙𝚞𝚕𝚕: Stay up-to-date with the rest of the team’s work by pulling in their changes.</p><p>🔗 𝚐𝚒𝚝 𝚛𝚎𝚖𝚘𝚝𝚎 -𝚟: Check your connections with this command that lists remote repositories linked to your local repo.</p><p>𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 𝘁𝗵𝗲 𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝗰𝗲𝘀</p><p>🔽 𝚐𝚒𝚝 𝚏𝚎𝚝𝚌𝚑 vs 𝚐𝚒𝚝 𝚙𝚞𝚕𝚕: Both bring data from remote repositories, but 𝚐𝚒𝚝 𝚏𝚎𝚝𝚌𝚑 is like previewing, while 𝚐𝚒𝚝 𝚙𝚞𝚕𝚕 is like downloading and updating your files in one go.</p><p>🔀 𝚐𝚒𝚝 𝚖𝚎𝚛𝚐𝚎 vs 𝚐𝚒𝚝 𝚛𝚎𝚋𝚊𝚜𝚎: Both integrate changes from one branch to another, but 𝚐𝚒𝚝 𝚖𝚎𝚛𝚐𝚎 makes a new commit for it, while 𝚐𝚒𝚝 𝚛𝚎𝚋𝚊𝚜𝚎 keeps your history neat and tidy.</p><p>↩️ 𝚐𝚒𝚝 𝚛𝚎𝚜𝚎𝚝 vs 𝚐𝚒𝚝 𝚛𝚎𝚟𝚎𝚛𝚝: Need to backtrack? Use 𝚐𝚒𝚝 𝚛𝚎𝚜𝚎𝚝 to discard changes or 𝚐𝚒𝚝 𝚛𝚎𝚟𝚎𝚛𝚝 to undo while keeping your commit history intact.</p><p>Git is an extremely powerful tool with plenty more commands and options.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e43dcb567421" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write a JavaScript program to reverse a given string.]]></title>
            <link>https://mdforhadsarker.medium.com/write-a-javascript-program-to-reverse-a-given-string-9a5410b8dbee?source=rss-60d6013110ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a5410b8dbee</guid>
            <category><![CDATA[toreversed]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[reversed]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Md Forhad Sarkar]]></dc:creator>
            <pubDate>Wed, 21 Feb 2024 08:27:29 GMT</pubDate>
            <atom:updated>2024-02-21T08:27:29.156Z</atom:updated>
            <content:encoded><![CDATA[<pre>const reverseString = (str) =&gt; str.split(&quot;&quot;).reverse().join(&quot;&quot;);</pre><ol><li>const reverseString = ...;: This defines a constant named reverseString. The constant is assigned a function. Once assigned, reverseString cannot be reassigned to something else, ensuring the function remains immutable within the scope of its definition.</li><li>(str) =&gt; ...: This is an arrow function that takes a single parameter, str, which represents the string to be reversed. Arrow functions provide a shorter syntax for writing functions in JavaScript. If there&#39;s only one parameter, you can omit the parentheses around the parameter, but keeping them makes the code clearer, especially to those new to JavaScript.</li><li>str.split(&quot;&quot;): This method splits the input string str into an array of individual characters. The split method takes a delimiter as an argument, and here the delimiter is an empty string (&quot;&quot;), meaning every character in the string str is split into its own element in the resulting array.</li><li>.reverse(): This method reverses the order of elements in an array. When called on the array of characters obtained from str.split(&quot;&quot;), it reverses the characters of the original string.</li><li>.join(&quot;&quot;): After reversing the array of characters, join(&quot;&quot;) concatenates all elements of the array back into a string. The join method takes a separator as an argument, and an empty string (&quot;&quot;) is used here, meaning that the characters are joined without any additional characters inserted between them.</li></ol><p>Putting it all together, reverseString is a function that takes a string str, splits it into an array of characters, reverses that array, and then joins the characters back into a string. This results in the reverse of the original string being returned.</p><pre>const result = reverseString(&quot;hello&quot;);<br>console.log(result); // Output: &quot;olleh&quot;</pre><p>The input &quot;hello&quot; is reversed to &quot;olleh&quot;, which is then output to the console.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a5410b8dbee" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>