<?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: Khwaja Billal Siddiqi</title>
    <description>The latest articles on DEV Community by Khwaja Billal Siddiqi (@billalsiddiqi).</description>
    <link>https://dev.to/billalsiddiqi</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%2F605804%2Fe93cd501-17b6-4ce7-b655-54d7ff6774d2.png</url>
      <title>DEV Community: Khwaja Billal Siddiqi</title>
      <link>https://dev.to/billalsiddiqi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/billalsiddiqi"/>
    <language>en</language>
    <item>
      <title>How to sort objects according to True and False values in Javascript</title>
      <dc:creator>Khwaja Billal Siddiqi</dc:creator>
      <pubDate>Thu, 15 Jun 2023 10:40:21 +0000</pubDate>
      <link>https://dev.to/billalsiddiqi/how-to-sort-objects-according-true-and-false-values-in-javascript-2b77</link>
      <guid>https://dev.to/billalsiddiqi/how-to-sort-objects-according-true-and-false-values-in-javascript-2b77</guid>
      <description>&lt;p&gt;You can sort an array of objects according to their boolean properties by the .sort() method. Here’s an example of how you can sort an array of objects with a boolean property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const users = [
    {
        name: "John",
        isVerified: false,
    },
    {
        name: "Kim",
        isVerified: true,
    },
    {
        name: "Mehdi",
        isVerified: false,
    },
]
users.sort((a,b) =&amp;gt;{ 
    if(a.isVerified &amp;amp;&amp;amp; !b.isVerified) {
        return -1;
    }else if (!a.isVerified &amp;amp;&amp;amp; b.isVerified){
        return 1;
    }else {
        return 0
    }
})
console.log(users);
// [
     { name: "Kim", isVerified: true },
     { name: "John", isVerified: false },
     { name: "Mehdi", isVerified: false }
   ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the .sort() method if the comparator function returns a value less than 0, it means that a should come before b in the sorted array. If it returns a value greater than 0, it means that b should come before a. If it returns 0, it means that the relative order of a and b doesn’t matter.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>array</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Reference Vs Value in JavaScript?</title>
      <dc:creator>Khwaja Billal Siddiqi</dc:creator>
      <pubDate>Sat, 13 May 2023 13:13:30 +0000</pubDate>
      <link>https://dev.to/billalsiddiqi/reference-vs-value-in-javascript-2dnf</link>
      <guid>https://dev.to/billalsiddiqi/reference-vs-value-in-javascript-2dnf</guid>
      <description>&lt;p&gt;In JavaScript, you can pass by value and by reference. The main difference between the two is that passing by value happens when assigning primitives while passing by reference when assigning objects.&lt;br&gt;
When you pass a primitive type variable like a string or a number into a function, you are passing it by value. This means that any changes to that variable within the function have no effect on the data outside of the function.&lt;br&gt;
On the other hand, when you pass an object into a function, you are passing it by reference. This means that if you change a property of that object within the function, that change will be reflected outside of the function as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let myNumber = 10;
let myObject = {value: 20};

function change(number, object) {
    number = number * 2;
    object.value = object.value * 2;
}

change(myNumber, myObject);
console.log(myNumber); // 10
console.log(myObject); // 40

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

&lt;/div&gt;



&lt;p&gt;In this example, myNumber is a primitive type and is passed by value into the change function. This means that any changes to the number parameter within the function have no effect on myNumber outside of the function.&lt;br&gt;
On the other hand, myObject is an object and is passed by reference into the change function. This means that when we change the value property of the object parameter within the function, that change is reflected in myObject.value outside of the function.&lt;/p&gt;

&lt;h6&gt;
  
  
  Follow me on &lt;a href="https://github.com/billalsiddiqi"&gt;Github&lt;/a&gt; &amp;amp;  &lt;a href="https://twitter.com/Siddiqi47"&gt;Twitter&lt;/a&gt;
&lt;/h6&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to monitor changes in JavaScript?</title>
      <dc:creator>Khwaja Billal Siddiqi</dc:creator>
      <pubDate>Wed, 03 May 2023 08:40:24 +0000</pubDate>
      <link>https://dev.to/billalsiddiqi/how-to-monitor-changes-in-javascript-1fof</link>
      <guid>https://dev.to/billalsiddiqi/how-to-monitor-changes-in-javascript-1fof</guid>
      <description>&lt;p&gt;For monitoring the changes that have been made to the DOM tree you can use MutationObserver.&lt;br&gt;
MutationObserver is a built-in object that observes a DOM element and fires a callback when it detects a change. It provides the ability to watch for changes being made to the DOM tree and is designed as a replacement for the older Mutation Events feature.&lt;/p&gt;

&lt;h6&gt;
  
  
  Some common use cases for MutationObserver include:
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;Augmenting third-party libraries that modify the DOM in some way but you want to extend this further or capture something from it.&lt;/li&gt;
&lt;li&gt;Reacting to changes in the DOM, such as when elements are created or when property changes occur.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To use MutationObserver, you first create an observer with a callback-function and then attach it to a DOM node. The config object specifies what kind of changes to react on, such as changes in the direct children of the node, changes in all descendants of the node, changes in attributes of the node, etc.&lt;/p&gt;

&lt;h6&gt;
  
  
  Here is an example adapted from MDN:
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const targetNode = document.getElementById("some-id");
const config = { attributes: true, childList: true, subtree: true };

// Callback function to execute when mutations are observed
const callback = (mutationList, observer) =&amp;gt; {
  for (const mutation of mutationList) {
    if (mutation.type === "childList") {
      console.log("A child node has been added or removed.");
    } else if (mutation.type === "attributes") {
      console.log(`The ${mutation.attributeName} attribute was modified.`);
    }
  }
};

const observer = new MutationObserver(callback);
observer.observe(targetNode, config);

// Later, you can stop observing
observer.disconnect();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  Follow me on &lt;a href="https://github.com/billalsiddiqi"&gt;Github&lt;/a&gt; &amp;amp;  &lt;a href="https://twitter.com/Siddiqi47"&gt;Twitter&lt;/a&gt;
&lt;/h6&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Local Storage: Store data into the user’s browser</title>
      <dc:creator>Khwaja Billal Siddiqi</dc:creator>
      <pubDate>Mon, 17 May 2021 16:21:06 +0000</pubDate>
      <link>https://dev.to/billalsiddiqi/local-storage-store-data-into-the-user-s-browser-2joj</link>
      <guid>https://dev.to/billalsiddiqi/local-storage-store-data-into-the-user-s-browser-2joj</guid>
      <description>&lt;p&gt;&lt;strong&gt;To avoid the long process of store a user's simple activities in the database is to store them in his/her browser.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Local Storage is key-value pairs and it’s read-only. So you can access Local Storage in Javascript via the window.localStorage property.&lt;/p&gt;

&lt;p&gt;For storing data you need to use setItem() which takes two parameters: a key and a value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;localStorage.setItem(‘name’, ‘Jonh Doe’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to store an array or an object you need to convert them into a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const seatsIndex= [1,4,5]
localStorage.setItem(‘selectedSeats’, JSON.stringify(seatsIndex));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For getting back the data from the Local Storage, use getItem() method. This one only accepts the key parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;localStorage.getItem(‘name’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you converted array or object to a string, for retrieving, you should convert it back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const selectedSeats = JSON.parse(localStorage.getItem(‘selectedSeats’));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For removing a single item, use removeItem() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;localStorage.removeItem(‘name’)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And For clearing all items, use clear() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;localStorage.clear()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Web browsers also have another storage called Session Storage and the difference between them is the Local Storage has no expiration date so the data not be deleted when the browser refreshed or closed, but the Session Storage deletes data when the tab is closed.&lt;/p&gt;

&lt;p&gt;note: do not store user’s sensitive data in Local Storage.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>browser</category>
      <category>frontend</category>
    </item>
    <item>
      <title>How to customize error messages in Laravel 8</title>
      <dc:creator>Khwaja Billal Siddiqi</dc:creator>
      <pubDate>Tue, 30 Mar 2021 14:47:16 +0000</pubDate>
      <link>https://dev.to/billalsiddiqi/how-to-customize-error-messages-in-laravel-8-jjo</link>
      <guid>https://dev.to/billalsiddiqi/how-to-customize-error-messages-in-laravel-8-jjo</guid>
      <description>&lt;p&gt;On a website, validation errors and full-page errors are ways to show the user that the request does not proceed so they should be as clear as crystal.&lt;/p&gt;

&lt;h3&gt;
  
  
  Customize Validation Errors
&lt;/h3&gt;

&lt;p&gt;For customizing the rule and attribute of validation Laravel has a separate file called validation.php in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources/lang/xx/validation.php.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you just want to edit the validation message you should define your custom message with attribute name in the “custom” array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'custom' =&amp;gt; [
    'name' =&amp;gt; [
        'required' =&amp;gt; 'Please Enter Your Name'
    ],
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For customizing the attributes name just add your attribute name in the “attributes” array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'attributes' =&amp;gt; [
    'name' =&amp;gt; 'Full Name',
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Customize Error Pages
&lt;/h3&gt;

&lt;p&gt;Laravel 8 error pages are in the vendor folder so you need to publish those pages into resources/views&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan vendor:publish --tag=laravel-errors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after publishing pages, you have access to them in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources/views/errors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Feel free to edit the messages or the whole layout.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to do maintenance on a live website (Laravel 8)</title>
      <dc:creator>Khwaja Billal Siddiqi</dc:creator>
      <pubDate>Tue, 30 Mar 2021 07:25:04 +0000</pubDate>
      <link>https://dev.to/billalsiddiqi/how-to-do-maintenance-on-a-live-website-laravel-8-3gjc</link>
      <guid>https://dev.to/billalsiddiqi/how-to-do-maintenance-on-a-live-website-laravel-8-3gjc</guid>
      <description>&lt;p&gt;Maintenance injects fresh blood into the application.&lt;/p&gt;

&lt;p&gt;After deploying your application to production it needs to be maintained. So Laravel makes it easy for you.&lt;br&gt;
To active maintenance mode, you just need to run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan down
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will disable your application and show a 503 error page for the user.&lt;/p&gt;

&lt;p&gt;By adding a secret key while you enable maintenance mode you can access the application even it’s in maintenance mode&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan down --secret="123456789"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://yourDomain.com/123456789 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What if you want to redirect all requests to a specific route? for doing that just add the flag of redirect while you enable maintenance mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan down --redirect=/about
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally after completing the maintenance run this command to disable maintenance mode &amp;amp; let the user enjoy using your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For digging deeper visit: Laravel Maintenance Mode&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
