<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Priyanshi Jain</title>
    <description>The latest articles on DEV Community by Priyanshi Jain (@priyanshijdev).</description>
    <link>https://dev.to/priyanshijdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1950364%2F8e933b25-d898-425f-a177-6304ab9a14cc.png</url>
      <title>DEV Community: Priyanshi Jain</title>
      <link>https://dev.to/priyanshijdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/priyanshijdev"/>
    <language>en</language>
    <item>
      <title>5 JavaScript Patterns I've Seen Senior Developers Use (And Why They Matter)</title>
      <dc:creator>Priyanshi Jain</dc:creator>
      <pubDate>Wed, 12 Nov 2025 15:31:06 +0000</pubDate>
      <link>https://dev.to/priyanshijdev/5-javascript-patterns-ive-seen-senior-developers-use-and-why-they-matter-3731</link>
      <guid>https://dev.to/priyanshijdev/5-javascript-patterns-ive-seen-senior-developers-use-and-why-they-matter-3731</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;My code used to work... but it wasn't good. Through pair programming and countless PR comments, I started noticing patterns that separated beginner code from production-ready code.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pattern 1: Early Returns (Guard Clauses)
&lt;/h2&gt;

&lt;p&gt;❌ &lt;strong&gt;How I used to write it:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function processUser(user) {
  if (user) {
    if (user.isActive) {
      if (user.hasPermission) {
        // actual logic here
        return doSomething(user);
      } else {
        return null;
      }
    } else {
      return null;
    }
  } else {
    return null;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ &lt;strong&gt;What I learned from seniors:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function processUser(user) {
  if (!user) return null;
  if (!user.isActive) return null;
  if (!user.hasPermission) return null;

  return doSomething(user);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 &lt;strong&gt;&lt;em&gt;Why it matters:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reduces nesting - No more "&lt;em&gt;pyramid of doom&lt;/em&gt;"&lt;/li&gt;
&lt;li&gt;Improves readability - Each condition is clear and isolated&lt;/li&gt;
&lt;li&gt;Easier to maintain - Adding/removing conditions is simple&lt;/li&gt;
&lt;li&gt;Lower mental load - You can scan the guards quickly&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Don't over-engineer simple logic.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Pattern 2: Object Lookup Instead of Switch/If-Else Chains
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;❌ How I used to write it:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getStatusMessage(status) {
  if (status === 'pending') {
    return 'Your order is pending';
  } else if (status === 'processing') {
    return 'We are processing your order';
  } else if (status === 'shipped') {
    return 'Your order has been shipped';
  } else if (status === 'delivered') {
    return 'Your order has been delivered';
  } else {
    return 'Unknown status';
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;✅ What I learned from seniors:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const STATUS_MESSAGES = {
  pending: 'Your order is pending',
  processing: 'We are processing your order',
  shipped: 'Your order has been shipped',
  delivered: 'Your order has been delivered'
};

function getStatusMessage(status) {
  return STATUS_MESSAGES[status] || 'Unknown status';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;💡 Why it matters:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More scalable - Adding new statuses is just one line&lt;/li&gt;
&lt;li&gt;Better performance - &lt;em&gt;O(1) lookup vs O(n)&lt;/em&gt; with if-else chains&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Pattern 3: Optional Chaining &amp;amp; Nullish Coalescing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;❌ How I used to write it:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getUserCity(user) {
  if (user &amp;amp;&amp;amp; user.address &amp;amp;&amp;amp; user.address.city) {
    return user.address.city;
  }
  return 'Unknown';
}

const limit = config.limit !== null &amp;amp;&amp;amp; config.limit !== undefined 
  ? config.limit 
  : 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;✅ What I learned from seniors:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getUserCity(user) {
  return user?.address?.city ?? 'Unknown';
}

const limit = config.limit ?? 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;💡 Why it matters:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;?. safely accesses nested properties - No more undefined errors&lt;/li&gt;
&lt;li&gt;?? only defaults on null/undefined - Preserves 0, false, and '' as valid values&lt;/li&gt;
&lt;li&gt;Modern JavaScript - Supported in all modern browsers (2020+)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Pattern 4: Destructuring with Defaults&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;❌ How I used to write it:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createUser(options) {
  const name = options.name || 'Anonymous';
  const age = options.age || 18;
  const role = options.role || 'user';

  return { name, age, role };
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;✅ What I learned from seniors:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createUser({ 
  name = 'Anonymous', 
  age = 18, 
  role = 'user' 
} = {}) {
  return { name, age, role };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;💡 Why it matters:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cleaner function signature - Parameters are self-documenting&lt;/li&gt;
&lt;li&gt;Handles missing object - The = {} prevents errors if nothing is passed&lt;/li&gt;
&lt;li&gt;Avoids falsy value issues - Same problem as Pattern 3 with ||&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Pattern 5: Composition Over Complex Conditionals&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;❌ How I used to write it:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function processData(data, shouldValidate, shouldTransform, shouldLog) {
  let result = data;

  if (shouldValidate) {
    result = validate(result);
  }

  if (shouldTransform) {
    result = transform(result);
  }

  if (shouldLog) {
    console.log(result);
  }

  return result;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;✅ What I learned from seniors:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pipe = (...fns) =&amp;gt; (value) =&amp;gt; 
  fns.reduce((acc, fn) =&amp;gt; fn(acc), value);

const processData = pipe(
  validate,
  transform,
  log
);

// Usage
const result = processData(data);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;💡 Why it matters:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single responsibility - Each function does one thing&lt;/li&gt;
&lt;li&gt;Easy to modify - Add/remove/reorder steps without touching logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;I'm still learning every day. If you're a senior developer reading this, what patterns would you add? If you're early in your journey like me, which of these resonates most with you?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's learn together in the comments. 👇&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>performance</category>
      <category>development</category>
    </item>
    <item>
      <title>How to access Objects?</title>
      <dc:creator>Priyanshi Jain</dc:creator>
      <pubDate>Wed, 28 Aug 2024 17:28:27 +0000</pubDate>
      <link>https://dev.to/priyanshijdev/how-to-access-objects-19kj</link>
      <guid>https://dev.to/priyanshijdev/how-to-access-objects-19kj</guid>
      <description>&lt;p&gt;As we can't access data from Object directly or perform operations on that.Firstly we have to convert the object in an array format then only we can apply functions .&lt;/p&gt;

&lt;p&gt;In JavaScript, you can access the properties and values of an object in several ways. Here are the most common methods:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1 . Dot Notation ()&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
 _the popular one _&lt;br&gt;
Ex:&lt;br&gt;
const person = {&lt;br&gt;
  name: "John",&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;console.log(person.name); // Output: John&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Bracket Notation&lt;/strong&gt; &lt;br&gt;
&lt;em&gt;(Suitable for when object contain spacing in key )&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;const person ={&lt;br&gt;
first name='Panchi';&lt;br&gt;
}&lt;br&gt;
 console.log(person['first name']);&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Accessing All Keys and Values [ IMP]&lt;/strong&gt;
You can use Object.keys(), Object.values(), or Object.entries() to get all keys, values, or both&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;const person = {&lt;br&gt;
  name: "John",&lt;br&gt;
  age: 30,&lt;br&gt;
  city: "New York"&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;console.log(Object.keys(person));   // Output: ["name", "age", "city"]&lt;br&gt;
console.log(Object.values(person)); // Output: ["John", 30, "New York"]&lt;br&gt;
console.log(Object.entries(person));// Output: [["name", "John"], ["age", 30], ["city", "New York"]]&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;** NOTE : Object.entries used to return array then on that resulting array we can apply like .map() or .filter function.**
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Moreover Resulting array contain data like enum in &lt;strong&gt;key value&lt;/strong&gt; pair&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
