<?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 Akash Sheikh on Medium]]></title>
        <description><![CDATA[Stories by Akash Sheikh on Medium]]></description>
        <link>https://medium.com/@nmakashsheikh?source=rss-8c62dddb8279------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OB4VTnJejwRdsHAINMRMcA.jpeg</url>
            <title>Stories by Akash Sheikh on Medium</title>
            <link>https://medium.com/@nmakashsheikh?source=rss-8c62dddb8279------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:41:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nmakashsheikh/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[কম্পিউটার, টার্মিনাল এবং Ruby কী?]]></title>
            <link>https://medium.com/@nmakashsheikh/%E0%A6%95%E0%A6%AE%E0%A7%8D%E0%A6%AA%E0%A6%BF%E0%A6%89%E0%A6%9F%E0%A6%BE%E0%A6%B0-%E0%A6%9F%E0%A6%BE%E0%A6%B0%E0%A7%8D%E0%A6%AE%E0%A6%BF%E0%A6%A8%E0%A6%BE%E0%A6%B2-%E0%A6%8F%E0%A6%AC%E0%A6%82-ruby-%E0%A6%95%E0%A7%80-5088e5a7bbcb?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/5088e5a7bbcb</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Mon, 06 Jul 2026 15:31:35 GMT</pubDate>
            <atom:updated>2026-07-06T15:45:56.044Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXeN9gcsE9OBhFac6toClA.png" /></figure><h4>১. Ruby কী?</h4><p><strong>Ruby</strong> একটি Programming Language।</p><p>যেমন: C, C++, Java, JavaScript তেমনি Ruby-ও একটি Programming Language।</p><p>Ruby দিয়ে তুমি বানাতে পারো:</p><ul><li>Wbsite</li><li>API</li><li>Automation Script</li><li>Desktop Tool</li></ul><p>উদাহরণ:</p><pre>puts &quot;Hello Akash&quot;</pre><p>এখানে puts মানে স্ক্রিনে কিছু দেখাও।</p><pre>Hello World</pre><h4>২. Ruby on Rails কী?</h4><p>Ruby দিয়ে অনেক কিছু করা যায়।</p><p><strong>Ruby on Rails (Rails)</strong> হলো Ruby দিয়ে ওয়েব অ্যাপ খুব দ্রুত তৈরি করার একটি Framework।</p><p>উদাহরণ:</p><ul><li>Facebook-এর মতো সাইট</li><li>Blog</li><li>E-commerce</li><li>School Management</li><li>Hospital Management</li><li>Inventory System</li></ul><p>সবই Rails দিয়ে তৈরি করা সম্ভব।</p><h4>৩. Framework কী?</h4><p>ধরো তুমি একটি বাড়ি বানাবে।</p><p>সব ইট, বালি, সিমেন্ট শুরু থেকে তৈরি না করে যদি আগে থেকেই একটি ভালো নকশা পাও, তাহলে কাজ অনেক সহজ হয়।</p><p>Rails ঠিক সেই নকশার মতো। এটি অনেক প্রস্তুত সুবিধা দেয়, তাই দ্রুত অ্যাপ বানানো যায়।</p><h4>৪. Terminal কী?</h4><p>Terminal হলো এমন একটি জায়গা যেখানে আমরা কমান্ড লিখে কম্পিউটারকে কাজ করতে বলি।</p><p>Windows-এ:</p><ul><li>Command Prompt (CMD)</li><li>PowerShell</li><li>Windows Terminal</li></ul><p>macOS/Linux-এ:</p><ul><li>Terminal</li></ul><p>Rails ডেভেলপমেন্টে Terminal প্রায় প্রতিদিন ব্যবহার করতে হবে।</p><h4>৫. প্রথম কমান্ড</h4><p>Terminal খুলে লিখো:</p><pre>pwd</pre><p>Linux/macOS-এ এটি বর্তমান ফোল্ডার দেখায়।</p><p>Windows PowerShell-এও pwd কাজ করে।</p><p>আরেকটি কমান্ড:</p><pre>ls</pre><p>এটি বর্তমান ফোল্ডারের ফাইল ও ফোল্ডার দেখায়।</p><p>Windows Command Prompt (CMD)-এ এর পরিবর্তে:</p><pre>dir</pre><h4>৬. নতুন ফোল্ডার তৈরি</h4><pre>mkdir my_project</pre><p>mkdir মানে <strong>Make Directory</strong>।</p><h4>৭. ফোল্ডারের ভিতরে যাও</h4><pre>cd my_project</pre><p>cd মানে <strong>Change Directory</strong>।</p><h4>৮. এক ধাপ পিছনে যাও</h4><pre>cd ..</pre><p><em>Happy Learning with Akash</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5088e5a7bbcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup MySQL in Docker]]></title>
            <link>https://medium.com/@nmakashsheikh/setup-mysql-in-docker-4050256c0a78?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/4050256c0a78</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Fri, 13 Dec 2024 10:50:17 GMT</pubDate>
            <atom:updated>2024-12-13T10:52:29.491Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/694/0*-oKn-RiBaWPPP0lq.png" /></figure><h4>Step 1: Install Docker</h4><pre>sudo apt-get update<br><br>sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin<br><br></pre><h4>Step 2: Pull MySQL Docker Image</h4><p>Pull the MySQL Docker image from the Docker Hub repository:</p><pre>docker pull mysql:latest</pre><h4>Step 3: Run MySQL Container</h4><p>Run a new MySQL container using the pulled image. Replace your_password with a secure password of your choice:</p><pre>docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=your_password -d mysql:latest</pre><ul><li>- -name mysql-container : Assigns a name to the running container.</li><li>- e MYSQL_ROOT_PASSWORD=your_password : Sets the root password for MYSQL.</li><li>- d mysql:latest : Runs the container in detached mode using the latest MYSQL image.</li></ul><h4>Stpe 4: Verify the Runnign Container</h4><p>Ensure the MySQL contianer is running:</p><pre>docker ps</pre><h4>Stpe 5: Connect to the MySQL Container</h4><p>To parsist data outside of the container, create a volumn:</p><pre>docker exec -it mysql-container mysql -uroot -p</pre><p>Enter the root password you specified earlier when prompted.</p><h4>Spep 6: Parsist Data with Volumes (Optional)</h4><p>To parsist data outside of the container, create a volume:</p><pre>docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=your_password -v mysql_data:/var/lib/mysql -d mysql:latest</pre><ul><li>-v mysql_data: /var/lib/mysql: Maps the mysql_data volume to the container’s /var/lib/mysql directory.</li></ul><h4>Step 7: Customize Configuration (Optional)</h4><p>To customize MySQL configuration, create a custom my.cnf file on your host machine and mount it to the container:</p><ol><li>Create a my.cnf file with your custom configuration.</li><li>Run the container with the configuration file mounted:</li></ol><pre>docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=your_password -v /path/to/my.cnf:/etc/mysql/my.cnf -d mysql:latest</pre><ul><li>-p 3306:3306: Maps the container&#39;s port 3306 to the host&#39;s port 3306.</li></ul><p>Now, you can connect to MySQL using local client with the following credentials:</p><ul><li>Host: localhost</li><li>Port: 3306</li><li>User: root</li><li>Password: your_password</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4050256c0a78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[String Features]]></title>
            <link>https://medium.com/@nmakashsheikh/string-features-b6a6d47a2c52?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6a6d47a2c52</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Fri, 10 Nov 2023 18:10:49 GMT</pubDate>
            <atom:updated>2023-11-10T18:14:07.645Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*WeBuM8e7CAIrTR1W.png" /></figure><p>In Java, a String is a class that represents a sequence of characters. It is one of the most commonly used classes in Java, and it is part of the java.lang package, so you don&#39;t need to import anything special to use it.</p><p>Here are some basic operations and features related to String in Java:</p><h4>Creating Strings:</h4><ul><li>You can create a string using the String literal or the new keyword.</li></ul><pre>String str1 = &quot;Hello, World!&quot;;<br>String str2 = new String(&quot;Hello, World!&quot;);</pre><h4>String Concatenation:</h4><ul><li>You can concatenate strings using the + operator.</li></ul><pre>String firstName = &quot;Akash&quot;;<br>String lastName = &quot;Sheikh&quot;;<br>String fullName = firstName + &quot; &quot; + lastName;  // Results in &quot;Akash Sheikh&quot;</pre><h4>String Length:</h4><ul><li>You can get the length of a string using the length() method.</li></ul><pre>String str = &quot;Java&quot;;<br>int length = str.length();  // Results in 4</pre><h4>Accessing Characters:</h4><ul><li>You can access individual characters in a string using the charAt() method.</li></ul><pre>char firstChar = str.charAt(0);  // Gets the first character &#39;J&#39;</pre><h4>Substring:</h4><ul><li>You can extract a substring from a string using the substring() method.</li></ul><pre>String part = str.substring(1, 3);  // Gets the substring from index 1 to 2 (&quot;av&quot;)</pre><h4>String Comparison:</h4><ul><li>You can compare strings using the equals() method for content comparison or compareTo() for lexicographical comparison.</li></ul><pre>String str1 = &quot;Java&quot;;<br>String str2 = &quot;Java&quot;;<br>boolean isEqual = str1.equals(str2);  // true</pre><h4>Immutable Nature:</h4><ul><li>Strings in Java are immutable, meaning their values cannot be changed after they are created. Operations that seem to modify strings actually create new string objects.</li></ul><h4>String Formatting:</h4><ul><li>You can format strings using methods like printf() or format() for more complex formatting.</li></ul><pre>String formattedString = String.format(&quot;Hello, %s!&quot;, &quot;World&quot;);<br>System.out.println(formattedString);  // Outputs: &quot;Hello, World!&quot;</pre><h4>String Methods:</h4><ul><li>The String class provides various methods for manipulating strings, such as toUpperCase(), toLowerCase(), trim(), and more.</li></ul><pre>String str = &quot;   Java Programming   &quot;;<br>String trimmedStr = str.trim();  // Removes leading and trailing whitespaces<br>String upperCaseStr = str.toUpperCase();<br>String lowerCaseStr = str.toLowerCase();</pre><p>These are just some basic features of the String class in Java. There&#39;s much more you can do with strings in Java, depending on your specific needs.</p><h3>-Akash Sheikh</h3><p>Jr. Software Engineer at Nitto Digital Services and Analytics Ltd.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6a6d47a2c52" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Java Program Works?]]></title>
            <link>https://medium.com/@nmakashsheikh/how-java-program-works-951142a16777?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/951142a16777</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Mon, 06 Nov 2023 09:43:45 GMT</pubDate>
            <atom:updated>2023-11-06T09:43:45.134Z</atom:updated>
            <content:encoded><![CDATA[<h3>Overview</h3><p>Java is a high-end programming language loved by many programmers for its interesting features. We cant run Java programs on a normal machine this is because high-level programming languages need to be translated into machine code first, due to this we run them on a <a href="https://www.scaler.com/topics/java/online-java-compiler/">Java compiler</a>.</p><p>The execution of a Java program consists of five steps which are</p><ol><li>Creation of a Java Program</li><li>Compiling a Java program,</li><li>Loading the program into the memory by Java Virtual Machine,</li><li>Java Virtual Machine verification for bytecode,</li><li>Java Program execution</li></ol><h3>Introduction</h3><p>When studying a programming language we need to understand the working and execution. Here we will be reading about the execution of a java program in detail and we will also understand what happens when we compile and execute a java program.</p><p>Java is a high-end programming language loved by many programmers for its interesting features. We cant run Java programs on a normal machine this is because high-level programming languages need to be translated into machine code first, due to this we run them on a Java compiler. It translates java language into the machine language making it easier for the machine to understand it. It is stated that it is a platform-independent language and does not work on the simple one-step compiling.</p><p>Now the first thing that we need to understand is how does the java programming language work? so let’s have a quick look.</p><h3>How Does Java Programming Language Work?</h3><p>The working of the Java programming language can be summed up in three steps. Let’s go through the steps given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*D56_ee0bcQCYrbpQ.png" /></figure><ol><li>Here for the first step, we need to have a java source code otherwise we won’t be able to run the program you need to save it with the program.java extension.</li><li>Secondly, we need to use a compiler so that it compiles the source code which in turn gives out the java bytecode and that needs to have a program.class extension. The Java bytecode is a redesigned version of the java source codes, and this bytecode can be run anywhere irrespective of the machine on which it has been built.</li><li>Later on, we put the java bytecode through the Java Virtual Machine which is an interpreter that reads all the statements thoroughly step by step from the java bytecode which will further convert it to the machine-level language so that the machine can execute the code. We get the output only after the conversion is through.</li></ol><p>So knowing about the working of java we need to understand the execution process of the program written in the language.</p><h3>Execution Process of Java Program</h3><p>The computer does not understand our human languages and it only understands codes that are in binary or coded form that means 0 or 1. During programming, there are a lot of steps that it undergoes-</p><ol><li><strong>Creation of a Java Program</strong>-When we talk about creating a program or typing a code that solves any kind of problem that we may have, it means physically writing the program on any text editor. You may or may not edit the program after you have written it once. When you create a program you don’t just make it and let it be the way it is you can modify it and save it on the device. But you need to save it with the java extension otherwise it would just appear as a normal text file.</li><li><strong>Compiling a Java Program</strong>-Now once the program is created and does not have any errors or mistakes we can go ahead and compile the program when you compile a program it means the compiler compiles the program and if there are no errors after compiling the program we can further run it and get the desired output. We compile the Java program in a command prompt or another console.</li><li><strong>Loading the Program into the Memory by Java Virtual Machine</strong>- A lot of memory is required by JVM when you want to load the .class file extension before the execution. Loading is the process of placing a program in memory for it to run. The .class files are needed by the program to execute the file.</li><li><strong>Java Virtual Machine verification for bytecode</strong>- Jvm has a bytecode verifier that is due to maintenance of the security of the program. The bytecode verifies the code only and only after the classes have been loaded in the memory to maintain the security of the program. It makes sure that the bytecodes are valid and accessible. It also saves the computer from various viruses and unsecure websites.</li><li><strong>Java Program Execution</strong>-The above steps are executed by JVM when it interprets the bytecode. Earlier JVM’s were slow and only interpreted one bytecode at a time. Nowadays the modern JVM’s are much faster as they use JIT(just-in-time) compilation units. These JVMs can execute various tasks at the same time. We also call them HotSpot compilers as they are used by JVM to find out the hot spots in our bytecode. Later on, the source code is converted bytecode into machine language.</li></ol><p>Let’s understand the tools that come in handy when we code in the java programming language.</p><ol><li><strong>Java Development Kit</strong> : As the name formally states Java development kit is a full-time kit that has a compiler, Java Runtime Environment(JRE), Debuggers, Java documents inclusive in it. For further execution in java, we need to have JDK installed on our computers to further lead on to the creation, compilation, and running of the java program. Here, as we use JDK we need an environment to run the programs.We use JRE Java Runtime Environment which provides the least requirements to execute the java program. It provides the JVM, Core classes and supporting files.</li><li><strong>Java Virtual Machine</strong> : This generally is referred to as JVM contains three phases that we have to follow. It is a very important part not only of JDK but also JRE as it is inbuilt in both of the places. When you run a program using the JRE amd JDK it also goes to the JVM as it is required to run the java program and it also interprets the program. The phases are as follows: <strong>Compile the Code:</strong> The Java Development Kit(JDK) provides us with the JAVAC compiler to get through with this step. <strong>Run the Code:</strong> JVM runs the bytecode that is provided by the compiler.</li><li><strong>Just in Time</strong>: Just in time, i.e JIT can be easily defined as a compiler that is witnessed in the manufacturing workflow and it aims directly at reducing the costs within the production systems and the flow times as well.</li><li><strong>Java Runtime Environment</strong>: JDK includes JRE. Which in turn after installation allows the java program to run. But we still can’t compile it. It has a browser, the applet supports, and a few plugins included in it. So, to run a java program on your respective computers you need JRE. JRE is made up of multiple elements altogether and they are:</li></ol><ul><li>Java virtual machine (JVM)</li><li>Java class libraries</li><li>Java class loader when our software tends to execute a particular program, it requires some environment to run in. Usually, it’s any operating system for example, Unix, Linux, Microsoft Windows, or the MacOS. Here our JRE acts as a translater and also a facilitator between the java program and the</li></ul><h3>Is Java a Compiler or Interpreter Based Language?</h3><p>When we talk about compilers we mean that- A tool that converts source code into machine language making it easier for the computer to interpret it is called a compiler.</p><p>Let’s have a look at the Java interpreter- As a compiler, an interpreter is also a programming tool that converts our source code into readable(for computers) machine code but it doesn’t work in the same way that the compiler does. It converts each statement going through it thoroughly before moving on to the next one and then executes it. No executor is needed for an interpreter.</p><p>hence we can conclude that we can consider java to be both <a href="https://www.scaler.com/topics/c/difference-between-compiler-and-interpreter/">compiler and interpreter</a> based language because the source code first gets compiled into binary code and then the same binary code runs on the JVm (Java Virtual Machine), and this is mostly a software-based interpreter</p><p>So since we have completely understood how the codes in java are executed let’s sum up what we just read.</p><h3>Summary</h3><ul><li>Java is an object oriented programming language.</li><li>During programming, there are 5 steps that we undergo to execute our programs which are</li><li>Creation of a Java program</li><li>Compiling a Java program</li><li>Loading the program into the memory by Java Virtual Machine</li><li>Java Virtual Machine verification for bytecode, Java Program execution.</li><li>There are 4 tools(JDK, JVM, JRE, JIT) that help us with the smooth working of our programs.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=951142a16777" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[map in JavaScript]]></title>
            <link>https://medium.com/@nmakashsheikh/map-in-javascript-f97339c0ed8e?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/f97339c0ed8e</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Thu, 21 Sep 2023 07:57:47 GMT</pubDate>
            <atom:updated>2023-09-21T07:57:47.514Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hlssi_Y8dsQ9QD6Z.jpg" /></figure><p>In JavaScript, the map method is used to transform the elements of an array into a new array. It creates a new array by applying a provided callback function to each element of the original array. The map function does not modify the original array; instead, it returns a new array containing the results of applying the callback to each element.</p><p>Here’s the basic syntax of the map method:</p><pre>array.map(callback(currentValue, index, array));</pre><ul><li>array: The array you want to iterate over.</li><li>callback: A function that is called for each element in the array. It takes three arguments: currentValue, index, and array.</li><li>currentValue: The current element being processed in the array.</li><li>index (optional): The index of the current element being processed.</li><li>array (optional): The array that map was called upon.</li></ul><p>Here’s a simple example that uses the map method to double each element in an array:</p><pre>const numbers = [1, 2, 3, 4, 5];<br><br>const doubled = numbers.map((value) =&gt; {<br>  return value * 2;<br>});<br><br>console.log(doubled); // Output: [2, 4, 6, 8, 10]</pre><p>In this example, the map method applies the provided callback function to each element of the numbers array, doubling each value and creating a new array called doubled.</p><p>You can also use the map method to transform objects or perform more complex operations on the elements of an array. Here&#39;s an example that transforms an array of objects:</p><pre>const people = [<br>  { name: &#39;Akash&#39;, age: 23},<br>  { name: &#39;Rahim&#39;, age: 25 },<br>  { name: &#39;Karim&#39;, age: 35 },<br>];<br><br>const names = people.map((person) =&gt; {<br>  return person.name;<br>});<br><br>console.log(names); // Output: [&quot;Akash&quot;, &quot;Rahim&quot;, &quot;Karim&quot;]</pre><p>In this example, the map method is used to extract the &quot;name&quot; property from each object in the people array, creating a new array of names.</p><p>Remember that the map method does not modify the original array; it produces a new array with the transformed values. If you want to modify the original array in-place, you should use methods like forEach or manually update the array elements within the map callback.</p><h3>-Akash Sheikh</h3><p>Jr. Software Engineer at Nitto Digital Services and Analytics Ltd.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f97339c0ed8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[filter in JavaScript]]></title>
            <link>https://medium.com/@nmakashsheikh/filter-in-javascript-bf5ca53835a?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf5ca53835a</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Thu, 21 Sep 2023 07:38:26 GMT</pubDate>
            <atom:updated>2023-09-21T07:38:26.398Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ly-liH1xWjgsyUUJ.png" /></figure><p>In JavaScript, the filter method is used to create a new array containing all elements from an existing array that satisfy a specified condition, as determined by a provided callback function. It does not modify the original array but instead returns a new array containing the filtered elements.</p><p>Here’s the basic syntax of the filter method:</p><pre>const newArray = array.filter(callback);</pre><ul><li>array: The array you want to filter.</li><li>callback: A function that is called for each element in the array. It takes three arguments: currentValue, currentIndex, and array. The callback should return true to include the element in the new array or false to exclude it.</li></ul><p>Here’s a simple example that uses the filter method to create a new array containing only even numbers from an array:</p><pre>const numbers = [1, 2, 3, 4, 5, 6, 7, 8];<br><br>const evenNumbers = numbers.filter((number) =&gt; {<br>  return number % 2 === 0;<br>});<br><br>console.log(evenNumbers); // Output: [2, 4, 6, 8]</pre><p>In this example, the filter method applies the callback function to each element of the numbers array and creates a new array containing only the elements that satisfy the condition (in this case, being even).</p><p>You can also use the filter method with more complex conditions. Here&#39;s an example that filters an array of objects to include only people who are older than 30:</p><pre>const people = [<br>  { name: &#39;Alice&#39;, age: 30 },<br>  { name: &#39;Bob&#39;, age: 25 },<br>  { name: &#39;Carol&#39;, age: 35 }<br>];<br><br>const olderThan30 = people.filter((person) =&gt; {<br>  return person.age &gt; 30;<br>});<br><br>console.log(olderThan30);<br>// Output: [{ name: &#39;Alice&#39;, age: 30 }, { name: &#39;Carol&#39;, age: 35 }]</pre><p>In this example, the filter method uses a callback function that checks if the age property of each person object is greater than 30, and it includes only those objects in the new array that meet this condition.</p><p>The filter method is a powerful tool for extracting elements from an array that match specific criteria, creating a new array that contains only the desired elements.</p><h3>-Akash Sheikh</h3><p>Jr. Software Engineer at Nitto Digital Services and Analytics Ltd.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf5ca53835a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Link]]></title>
            <link>https://medium.com/@nmakashsheikh/link-38abcce7cdec?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/38abcce7cdec</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Wed, 12 Jul 2023 07:53:55 GMT</pubDate>
            <atom:updated>2023-07-12T07:53:55.566Z</atom:updated>
            <content:encoded><![CDATA[<p>Free Platforms to Learn Coding</p><p>HTML — <a href="https://html.com/">https://html.com</a><br>CSS — <a href="https://web.dev/learn/css">https://web.dev/learn/css</a><br>JavaScript — <a href="https://javascript.info/">https://javascript.info</a><br>React- <a href="https://reactplay.io/">https://reactplay.io</a><br>Vue.js — <a href="https://learnvue.co/">https://learnvue.co</a><br>Git — <a href="https://lnkd.in/dfC8aezN">https://lnkd.in/dfC8aezN</a><br>Web3 — <a href="https://learnweb3.io/">https://learnweb3.io</a><br>Python — <a href="https://learnpython.org/">https://learnpython.org</a><br>SQL — <a href="https://lnkd.in/dRi_jM3i">https://lnkd.in/dRi_jM3i</a><br>BlockChain — <a href="https://cryptozombies.io/">https://cryptozombies.io</a><br>Nextjs — <a href="https://lnkd.in/dX3HssN5">https://lnkd.in/dX3HssN5</a><br>Al — <a href="https://lnkd.in/d2vp3qWt">https://lnkd.in/d2vp3qWt</a><br>ML — <a href="https://lnkd.in/dGHzEB73">https://lnkd.in/dGHzEB73</a><br>PHP — <a href="https://phptherightway.com/">https://phptherightway.com</a><br>API -<a href="https://rapidapi.com/learn">https://rapidapi.com/learn</a><br>GO-<a href="https://learn-golang.org/">https://learn-golang.org</a><br>Rust — <a href="https://lnkd.in/dNDZnJnv">https://lnkd.in/dNDZnJnv</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38abcce7cdec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React useEffect Hooks]]></title>
            <link>https://medium.com/@nmakashsheikh/react-useeffect-hooks-22fecd39be72?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/22fecd39be72</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Mon, 10 Jul 2023 17:53:22 GMT</pubDate>
            <atom:updated>2024-02-10T06:59:34.268Z</atom:updated>
            <content:encoded><![CDATA[<h3>useEffect Hooks</h3><p>React.useEffect হচ্ছে React এর একটি বিল্ট-ইন hook যেটার মাধ্যমে আমরা আমাদের যেকোনো কাস্টম কোড রান করাতে পারি React render এবং re-render এর পরে।</p><pre>React.useEffect(() =&gt; { // 1 -&gt; callback function<br>  // your side-effect code here.<br>}, [] // 2 -&gt; dependency array)</pre><p>উপড়ের কোডের ভিতরে আমরা একটু খেয়াল করে দেখি যে আমি ১, ২ দিয়ে ২ টি জায়গায় লেবেলিং করেছি। আমাদেরকে React.useEffect এর কাজ বুঝতে হলে এই ১ এবং ২ পয়েন্ট ২টী ভালমতো বুঝা লাগবে।</p><p>১। কলব্যাক ফাংশনঃ আমরা দেখতে পাচ্ছি প্রথমে যে React.useEffect একটি কলব্যাক ফাংশন একসেপ্ট করে, মূলত এই ফাংশনের ভিতরেই আমরা আমাদের সাইড এফেক্ট কোডের লজিক লিখে থাকি। এখন প্রশ্ন হচ্ছে সাইড এফেক্ট অথবা এফেক্ট বলতে আমরা কি বুঝাচ্ছি? সাইড এফেক্ট বলতে আমরা এমন যেকোনো কিছুকে বুঝাই যেটা ফাংশনের স্কোপের বাহিরের কোন কিছুর উপর প্রভাব ফেলে। উদাহরণস্বরূপ নেটওয়ার্ক রিকোয়েস্ট, সাবস্ক্রিপ্সন সেটআপ, DOM কে ম্যানুয়ালি চেঞ্জ করা ইত্যাদি।</p><p>আচ্ছা তাহলে এখন প্রশ্ন আসতে পারে আমরা তো এই useEffect কে আমাদের কম্পোনেন্টের ভিতরে কোথাও call ই তো করছি না তাহলে এটা কখন রান হবে? কারন আমরা জানি কোন ফাংশনকে কল করলেই সেটি শুধুমাত্র রান হয়। এখানেই তো useEffect এর আসল কাহিনী। useEffect ফাংশনটি প্রতিবার render এবং re-render এর পরে কল হয়। এটা আমাদের কল করা লাগে না, React নিজেই এটা কল করে থাকে।</p><pre>export default function App() {<br>  const [count, setCount] = useState(0)<br>  <br>  useEffect(() =&gt; {<br>    console.log(&#39;use effect being called&#39;)<br>  })<br><br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;button onClick={()=&gt;setCount(count+1)}&gt;Click&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>আমরা যদি উপড়ের এই কোডটি লিখে রান করি তাহলে দেখব আমরা আমাদের কম্পোনেন্ট মাউন্ট হওয়ার পরে console এ ‘use effect being called’ এই লাইনটা দেখতে পারছি। আবার আমরা প্রত্যেকবার বাটন ক্লিক করার পর যখন ষ্টেট আপডেট করছি তার পরেও কনসোলে এই সেইম লগটি দেখতে পারব। কারণ আমরা আগেই বলেছি যে React প্রতিবার render and re-render এর পরে আমাদের useEffect কে কল করে থাকে। নিচের ছোট ক্লিপটি দেখলে ব্যাপারটা আরও ক্লিয়ার হবে।</p><p><a href="https://saadbashar.com/wp-content/uploads/2021/07/useeffect.mov">https://saadbashar.com/wp-content/uploads/2021/07/useeffect.mov</a></p><p>আশা করা যায় আমরা কলব্যাক ফাংশন কি এবং কখন কল হয়ে থাকে সেটি নিয়ে একটি ক্লিয়ার আইডিয়া পেলাম।</p><p>২। effect dependencies</p><p>এখন আমরা ২ নং লেবেলিং এর দিকে খেয়াল করি। আমরা দেখতে পারছি সেখানে একটি ফাকা array ডিক্লেয়ার করা আছে। এটার কাজ কি আসলে? এটা কে বলা হয় dependency array. এটাকে dependency array বলার কারণ হচ্ছে আমাদের useEffect কল হবে কি না হবে সেটি এই array এর ইনপুট এর উপর depend করে। একটু আগে আমরা দেখে আসলাম যে useEffect প্রতিবার render এবং re-render হওয়ার পরেই কিন্তু কল হচ্ছে, কারণ সেখানে আমরা কোন dependency array ব্যাবহার করিনি, তাই এটি সবসময় কল হচ্ছিল।</p><p>কিন্তু আমরা চাইলেই আমাদের useEffect এর কলব্যাক ফাংশনকে কিছু ইনপুটের উপর নির্ভরশীল করে দিতে পারি। এই ইনপুট হতে পারে যেকোনো state, props or function. আমরা নিচের উদাহরণটি তাহলে দেখি</p><pre>export default function App() {<br>  const [count, setCount] = useState(0);<br>  const [name, setName] = useState(&quot;&quot;);<br>  <br>  useEffect(() =&gt; {<br>    console.log(&quot;use effect depends on count&quot;);<br>  }, [count]);<br><br>  useEffect(() =&gt; {<br>    console.log(&quot;use effect depends on name&quot;);<br>  }, [name]);<br><br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Set count&lt;/button&gt;<br>      &lt;button style={{ marginLeft: 20 }} onClick={() =&gt; setName(&quot;saad&quot;)}&gt;<br>        Set name<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>এখানে আমরা দেখতে পারছি যে 2টি useEffect ব্যাবহার করা হয়েছে। প্রথমটার dependency array এর ইনপুট হচ্ছে count state এবং দ্বিতীয়টি ইনপুট হচ্ছে name state. তারমানে আমরা বুঝাচ্ছি যে প্রথম useEffect শুধুমাত্র তখনি কল হবে যখন ইনপুটের count value change হয়, ঠিক তেমনি দ্বিতীয় useEffect শুধুমাত্র তখনি কল হবে যখন ইনপুটের name value change হয়. এই ভিডিওটি দেখলে ব্যাপারটি ক্লিয়ার হবে। খেয়াল করি আমরা কখন কোনটি লগ হচ্ছে কনসোলে।</p><p><a href="https://saadbashar.com/wp-content/uploads/2021/07/useeffect-1.mov">https://saadbashar.com/wp-content/uploads/2021/07/useeffect-1.mov</a></p><p><a href="https://saadbashar.com/wp-content/uploads/2021/07/useeffect-1.mov">https://saadbashar.com/wp-content/uploads/2021/07/useeffect-1.mov</a></p><p>আশা করি তাহলে আমরা dependency array সম্পর্কেও একটি পরিষ্কার ধারনা পেলাম। এখানে আরেকটি জিনিস আমরা মাঝে মাঝেই খেয়াল করে থাকি যে আমাদের dependency array হচ্ছে ফাকা, মানে []</p><pre>export default function App() {<br>  const [count, setCount] = useState(0)<br>  <br>  useEffect(() =&gt; {<br>    console.log(&#39;use effect being called&#39;)<br>  }, [])<br><br>return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;button onClick={()=&gt;setCount(count+1)}&gt;Click&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>আমাদের প্রথম উদাহরনে যদি আমরা এরকম একটু ফাকা array ব্যাবহার করি তাহলে দেখব এটি শুধুমাত্র একবার কল হবে, এমনকি আমরা যদি কোন ষ্টেটকে চেঞ্জ করি তাও। নিচের লগের দিকে লক্ষ্য করি।</p><p><a href="https://saadbashar.com/wp-content/uploads/2021/07/empty-array.mov">https://saadbashar.com/wp-content/uploads/2021/07/empty-array.mov</a></p><p>আমাদের প্রথম উদাহরনে যদি আমরা এরকম একটু ফাকা array ব্যাবহার করি তাহলে দেখব এটি শুধুমাত্র একবার কল হবে, এমনকি আমরা যদি কোন ষ্টেটকে চেঞ্জ করি তাও।</p><p>এটিই ছিল সহজ বাংলায় useEffect hook এর উপরে একটি ছোট ব্যাখ্যা। আশা করি কারোর উপকার হবে ইনশাল্লাহ।</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22fecd39be72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Hooks]]></title>
            <link>https://medium.com/@nmakashsheikh/react-hooks-6121db15ebea?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/6121db15ebea</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Mon, 10 Jul 2023 17:37:11 GMT</pubDate>
            <atom:updated>2023-07-10T17:37:11.260Z</atom:updated>
            <content:encoded><![CDATA[<p>React এর ডকুমেন্টেশন থেকে আমরা জানতে পারি hooks হচ্ছে react এর নতুন এডিশন যেটার মাধ্যমে আমরা React এর স্টেট এবং অন্যান্য ফিচার ব্যাবহার করতে পারব class component না লিখেই, অর্থাৎ ফাংশনাল কম্পোনেন্টের মাধ্যমেই।</p><p>যেকোনো ইন্টারেক্টিভ অ্যাপ্লিকেশনে আমাদের অ্যাপের স্টেট ধরে রাখা লাগে (store) কোথাও না কোথাও এবং এই স্টেট এর ডিপেন্ড করেই কিন্তু আমরা আমাদের আপ্লিকেশনকে ইন্টারেক্টিভ করে থাকি।</p><p>এখন আসা যাক তাহলে React এ। আমরা React এ কিছু স্পেশাল ফাংশন ব্যাবহার করে থাকি আমাদের অ্যাপকে ইন্টারেক্টিভ করার জন্যে। এই ফাংশন গুলোকেই আমরা “Hooks” বলি। React আমাদের এরকম কিছু কমন বিল্ট-ইন hooks দিয়ে দিয়েছে।</p><ul><li>React.useState</li><li>React.useEffect</li><li>React.useContext</li><li>React.useRef</li><li>React.useReducer</li></ul><p>এখানে প্রত্যেকটি একটি স্পেশাল ফাংশন যেটার কথা আমরা একটু আগেই জেনে এসেছি। আমরা এই ফাংশনগুলোর মাধ্যমে আমাদের React কম্পোনেন্টে ডাটা স্টোর করতে পারি (যেমন স্টেট) অথবা আমরা বিভিন্ন অ্যাকশান পারফর্ম করতে পারি (সাইড ইফেক্ট)। উপড়ের hooks গুলো ছাড়াও আরও কিছু বিল্ট-ইন hooks আছে যেগুলো আমাদের ক্ষেত্রবিশেষে ব্যাবহার করা লাগে।</p><p>এখানে ইম্পরট্যান্ট ব্যাপার হচ্ছে যে প্রত্যেকটি hooks এরই কিন্তু নিজস্ব Unique API রয়েছে। কিছু hooks শুধুমাত্র একটি value রিটার্ন করে (যেমন React.useRef এবং React.useContext), আবার কিছু আছে যারা একটি pair of values রিটার্ন করে থাকে। (যেমন React.useState and React.useReducer) এবং বাকিরা কিছুই রিটার্ন করে না (যেমন React.useEffect)।</p><p>আশা করি আমরা hooks এর একটি বেকগ্রাউন্ড পেয়েছি উপড়ের আলোচনায়। এখন আমরা আলোচনা করবো আমাদের প্রথম হুক useState নিয়ে।</p><h3>useState</h3><p>আমরা সম্ভবত এই hook টি সবথেকে বেশি ব্যাবহার করে থাকি আমাদের অ্যাপে। কারণ আমরা এটির মাধ্যমেই আমরা আমাদের ইন্টারনাল স্টেট মেনেজ করে থাকি। মূল আলোচনায় যাওয়ার আগে আমরা আগে দেখে নেই কোডে এটির ব্যাবহার –</p><pre>function Counter() {<br>  const [count, setCount] = React.useState(0)<br>  const increment = () =&gt; setCount(count + 1)<br>  return &lt;Pressable onPress={increment}&gt;{count}&lt;/Pressable&gt;<br>}</pre><p>আমরা প্রথমে এই লাইনের ব্যাখ্যায় আসি; const [count, setCount] = React.useState(0)</p><p>এখানে আমরা দেখতে পারছি, React.useState(0) হচ্ছে একটি ফাংশন যেটি এটি একটি initial value গ্রহন করে। তো আমাদের ক্ষেত্রে আমাদের ষ্টেটের initial value হচ্ছে 0।</p><p>এই ফাংশনটি আসলে কি রিটার্ন করে আমাদের জন্যে? React.useState এক জোড়া (২টি) value রিটার্ন করে এবং এই জোড়া value টি একটি array টাইপে রিটার্ন হয়ে আসে যেটার ভিতরে ২টি এলেমেন্ট থাকে। আমরা যদি console.log দিয়ে এটার রিটার্ন দেখি তাহলে বুঝতে আরও সুবিধা হবে।</p><pre>const a = React.useState(0)<br>console.log(&quot;useState&quot;,  a) -----&gt; [0, f()] // output</pre><p>আমরা দেখতে পারছি আমরা যদি console.log করি আমাদের useState কে, তাহলে আমরা রিটার্ন এ একটি array পাই যেটার ভিতরে ২ টি এলেমেন্ট আছে, ফার্স্ট ইনডেক্সে আমাদের initial value 0 পাই এবং সেকেন্ড ইনডেক্সে আমরা একটি ফাংশন পাচ্ছি এবং এই ফানশনের মাধ্যমেই আমরা আমাদের ষ্টেট ডাটা আপডেট করি। কমন প্রাকটিস হচ্ছে আমরা সবসময় এই ২টি value কে array destructuring এর মাধ্যমে ২টি ভেরিয়েবেলে সেট করে দেই।</p><p>আমরা পাচ্ছি তাহলে [count, setCount] = [0, f()], count এর value হচ্ছে 0. (আমাদের array এর ইনডেক্স 0) এবং setCount এর value হচ্ছে আমাদের ফাংশনটি যেটি আমরা array এর ইনডেক্স ১ এ কিন্তু দেখেছি। আশা করি আমরা array destructuring টি বুঝতে পেরেছি। নিচে array destructuring কিভাবে কাজ করে সেটি দেখানো হল।</p><pre>let a, b, rest;<br>[a, b] = [10, 20];</pre><pre>console.log(a);<br>// expected output: 10</pre><pre>console.log(b);<br>// expected output: 20</pre><pre>[a, b, ...rest] = [10, 20, 30, 40, 50];</pre><pre>console.log(rest);<br>// expected output: Array [30,40,50]</pre><p>ভালো কথা, আমরা যে এতক্ষণ ষ্টেট ষ্টেট করলাম, আসলে ষ্টেট টা কি? এটার সংজ্ঞায় বলা যায় যে, ষ্টেট হচ্ছে এমন একটি ডাটা অথবা ভেলু যেটা চেঞ্জ হয় সময়ের সাথে। তাহলে আসলে কিভাবে চেঞ্জ হয় আমাদের ষ্টেট। আমরা যদি আমাদের Counterএ ফিরে যাই তাহলে দেখব আমরা যখন বাটন ক্লিক করছি তখন আমরা একটি ফাংশন কল করছি, সেটি হল increment এবং এই ফাংশনের ভিতরে আমরা আমাদের ষ্টেটকে আপডেট করে দিচ্ছে আমাদের setCount এর মাধ্যমে। এই setCount কিন্তু আমরা সেই প্রথমেই destructuring করে পেয়েছি এবং এই ফাংশনের কাজই হচ্ছে আমাদের count ষ্টেটকে আপডেট করা।</p><p>ওকে, তাহলে আমরা ষ্টেট পেলাম আবার ষ্টেট কে আপডেটও করলাম, তাহলে এখন কি হবে? এখানেই আসলে React এর মজা। আমরা যখন setCount ফাংশনটি call করি তখন আসলে আমরা React কে বলি যে আমাদের state আপডেট হয়েছে, React তখন পুরো Counter কে আবার রেন্ডার করে, আর যখন এটি re-render হয় তখন আমাদের পুরো কম্পোনেন্ট ফাংশনটি আবার re-run হয়। এবং এই re-run হওয়ার মাধ্যমে আমরা আমাদের আপডেটেড ষ্টেট value টি পাই।</p><p>প্রথমে আমাদের counter state এর value হচ্ছে 0, পরে setCount কল হলে আমরা এটার value ১ বাড়িয়ে দেই। React তখন পুরো Counter কম্পোনেন্টকে আবার রেন্ডার করে এবং নেক্সট রানে আমাদের counter এর value হয় ১। এই counter এর value কম্পোনেন্ট রিমুভ হওয়ার আগে পর্যন্ত বিদ্যমান থাকে।</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6121db15ebea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding DOM Manipulation with JavaScript]]></title>
            <link>https://medium.com/@nmakashsheikh/understanding-dom-manipulation-with-javascript-77be5ff7f809?source=rss-8c62dddb8279------2</link>
            <guid isPermaLink="false">https://medium.com/p/77be5ff7f809</guid>
            <dc:creator><![CDATA[Akash Sheikh]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 09:11:55 GMT</pubDate>
            <atom:updated>2023-07-07T09:16:18.218Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6GZ-5AXV7jbR40Dg.jpg" /></figure><p>Document Object Model or DOM is a programming interface that allows JavaScript to manipulate elements in an HTML document.</p><p>When an HTML code is loaded in a browser, it parses it. In order to make these web pages and HTML documents dynamic, the browser lets JavaScript tap into the power of the DOM to access nodes and elements within the HTML file in a hierarchical form.</p><p>DOM is an Application Programming Interface (API) for accessing and manipulating HTML files.</p><p>In this article, we will look at how to use the document object to select elements, traverse the DOM, insert, remove, and replace elements.</p><h3>Selecting Elements in the DOM</h3><p>You can select elements within the Document Object Model (DOM) using various methods available through the document object. These methods allow you to select either a single element or multiple elements. These methods are:</p><h3>getElementById()</h3><p>document.getElementById() access elements with a specific id that matches the one mentioned in the string.</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>               &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>                &lt;h1 id=&quot;heading&quot;&gt; JavaScript getElementById() <br>              &lt;/h1&gt;<br>            &lt;ul class=&quot;parent&quot;&gt;<br>                   &lt;li class=&quot;item&quot;&gt;First Item&lt;/li&gt;<br>                   &lt;li class=&quot;item&quot;&gt;Second Item&lt;/li&gt;<br>              &lt;/ul&gt;<br>          &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const element = document.getElementById(&quot;heading&quot;);</pre><p>The id is unique within an HTML document. However, HTML is a forgiving language. If the HTML document has multiple elements with the same id, the document.getElementById() method returns the first element it encounters. In cases where the ID given does not exist, it returns null.</p><h3>getElementByClassName()</h3><p>document.getElementByClassName() is used to access elements with specific class names. These names would be passed as arguments to the method when it is called.</p><p>It returns an array-like (not everything you can do on an array works there) object of the child elements with a specified class name.</p><p>These arrays are called HTML collections and are different from true Javascript arrays. Therefore, not all array operations can work with these HTML collections.</p><p>Just like document.getElementById(), document.getElementByClassName() method returns the first element it encounters. In cases where the class name given does not exist, it returns null.</p><p>Here is a code snippet that describes how getElementsByClassName() works with HTML elements:</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>               &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>                &lt;nav&gt;<br>                &lt;ul class=&quot;parent&quot;&gt;<br>                    &lt;li class=&quot;item&quot;&gt;First Item&lt;/li&gt;<br>                    &lt;li class=&quot;item&quot;&gt;Second Item&lt;/li&gt;<br>                 &lt;/ul&gt;<br>                &lt;/nav&gt;<br>          &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const items = document.getElementsByClassName(&quot;item&quot;);</pre><p>In the code snippet, the first element with the class item is selected and stored in a variable items.</p><h3>querySelector()</h3><p>document.querySelector() is a method that allows you to select the first element that matches the CSS selector.</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>               &lt;nav&gt;<br>               &lt;ul&gt;<br>                    &lt;li class=&quot;item&quot;&gt;First Item&lt;/li&gt;<br>                  &lt;li class=&quot;item&quot;&gt;Second Item&lt;/li&gt;<br>                  &lt;li class=&quot;item&quot;&gt;Third Item&lt;/li&gt;<br>               &lt;/ul&gt;<br>               &lt;/nav&gt;<br>          &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const items = document.querySelector(&quot;li&quot;);<br>console.log(items);</pre><p>In this code, the js script uses the document.querySelector(&quot;li&quot;) to select the first li element.</p><h3>Selecting Multiple Elements in the DOM</h3><p>When it comes to selecting multiple elements within the DOM, there are several methods you can use. These methods typically return a collection of elements that matches specific criteria. Here are some commonly used approaches:</p><h3>querySelectorAll()</h3><p>document.querySelectorAll() is used to select all elements with a CSS selector. It returns a static NodeList of elements. This means it does not change or reflect when tag names are deleted or added.</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>               &lt;nav&gt;<br>               &lt;ul&gt;<br>                    &lt;li class=&quot;item&quot;&gt;First Item&lt;/li&gt;<br>                  &lt;li class=&quot;item&quot;&gt;Second Item&lt;/li&gt;<br>                  &lt;li class=&quot;item&quot;&gt;Third Item&lt;/li&gt;<br>               &lt;/ul&gt;<br>               &lt;/nav&gt;<br>          &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const items = document.querySelectorAll(&quot;li&quot;);<br>console.log(items);</pre><p>From the above JavaScript code, we can easily select all the elements with the li CSS selector.</p><p><strong>P S:</strong> This should not be confused with querySelector(). querySelector() selects just the first element with a specific CSS selector. While querySelectorAll() selects all elements with a specific CSS selector</p><h3>getElementByTagName()</h3><p>document.getElementByTagName() allows the selection of all elements that match a tag name. It returns a live HTMLCollection of elements. This means it automatically reflects changes when tag names are deleted or added. For example,</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>                &lt;h1&gt;Tag Name 1&lt;/h1&gt;<br>                &lt;p&gt;This is for some random text&lt;/p&gt;<br>               &lt;h1&gt;Tag Name 2&lt;/h1&gt;<br>                &lt;p&gt;This is for some more random text&lt;/p&gt;<br>                &lt;h1&gt;Tag Name 3&lt;/h1&gt;<br>                &lt;p&gt;This is for some other random text&lt;/p&gt;<br>          &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const headings = document.getElementsByTagName(&quot;h1&quot;);<br>console.log(headings);</pre><p>In the JavaScript code snippet, all of the elements with the tag name h1 are selected and displayed.</p><h3>Traversing the DOM</h3><p>DOM Traversing is the process of moving or selecting an element from another element.</p><p>It involves navigating the Document Object Model(DOM) tree to access and manipulate elements.</p><p>Traversing can occur in three directions:</p><ul><li>Upwards</li><li>Sideways</li><li>Downwards</li></ul><h3>Upward traversing</h3><p>This involves accessing a child element from its parent element or ancestors. The most common method used for upward traversing is parentElement().</p><h4>Using parentElemet or parentNode</h4><p>You can traverse up the DOM using parentElement() or parentNode(). This lets you access the element/node that encloses the current element.</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>         &lt;body&gt;<br>            &lt;ul class=&quot;parent&quot;&gt;<br>                &lt;li class=&quot;child&quot;&gt;First Item&lt;/li&gt;<br>               &lt;li class=&quot;child&quot;&gt;Second Item&lt;/li&gt;<br>                &lt;li class=&quot;child&quot;&gt;Third Item&lt;/li&gt;<br>             &lt;/ul&gt;<br>         &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const item = document.querySelector(&quot;.child&quot;);<br>const parentN = item.parentNode<br>const parentEl = item.parentElement<br>console.log(parentN);<br>console.log(parentEl)</pre><p>In the JavaScript code snippet, the first element with the class child is selected and stored in a variable item. Now, we can use the parentNode and parentElement methods to access this element&#39;s parent node and parent element.</p><h3>Sideways traversing</h3><p>This involves moving between elements that share the same parent. These elements are also referred to as sibling elements. The most common methods used for sideways traversing are nextElementSibling and previousElementSibling</p><h4>Using nextElementSibling and previousElementSibling</h4><p>When navigating the DOM sideways we can select the next element using nextElementSibling and select the previous element using previousElementSibling.</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>            &lt;ul class=&quot;parent&quot;&gt;<br>                &lt;li class=&quot;child&quot;&gt;First Item&lt;/li&gt;<br>               &lt;li class=&quot;child&quot;&gt;Second Item&lt;/li&gt;<br>                &lt;li class=&quot;child&quot;&gt;Third Item&lt;/li&gt;<br>             &lt;/ul&gt;<br>         &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const firstItem = document.querySelector(&quot;li&quot;);<br>console.log(firstItem.nextElementSibling);<br>const secondItem = document.querySelectorAll(&quot;li&quot;)[1];<br>console.log(secondItem.previousElementSibling);</pre><p>This might be a bit confusing so let’s break down the code:</p><p><strong>Line 1</strong> we select the first element with the tag name li and store it in a variable named firstItem.</p><p><strong>Line 2</strong> we easily access the next element of the firstItem using the nextElementSibling method.</p><p><strong>In line 3</strong> we use querySelectorAll() to access all elements with the tag li, then we use the index [1] to select just the second element with the tag li, storing it in a variable named secondItem”</p><p><strong>Line 4</strong> we easily access the previous element of secondItem using the previousElementSibling() method.</p><p><strong>PS</strong>: This should give further clarity on the differences between querySelector() and querySelectorAll() and how they are used.</p><h3>Downward Traversing</h3><p>This involves moving from a parent element to its child elements. In navigating the DOM downwards, we can use the children property to select direct descendants of the current element.</p><h4>Selecting children Element</h4><p>In navigating the DOM downwards, we can use the children property to select direct descendants of the current element.</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>            &lt;ul class=&quot;parent&quot;&gt;<br>                &lt;li class=&quot;child&quot;&gt;First Item&lt;/li&gt;<br>               &lt;li class=&quot;child&quot;&gt;Second Item&lt;/li&gt;<br>                &lt;li class=&quot;child&quot;&gt;Third Item&lt;/li&gt;<br>             &lt;/ul&gt;<br>         &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const parent = document.querySelector(&quot;.parent&quot;);<br>const children = parent.children;</pre><p>In the JavaScript code snippet, the first element with the class parent is selected and stored in a variable parent. Now, we can use the children method to access the element&#39;s descendants.</p><h3>Creating HTML Elements in JavaScript</h3><p>We can create new HTML elements from a Javascript code using the document.createElement() method. This method takes an argument of the type of element we want to create.</p><p>For example:</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>            &lt;ul class=&quot;parent&quot;&gt;<br>                &lt;li class=&quot;child&quot;&gt;First Item&lt;/li&gt;<br>               &lt;li class=&quot;child&quot;&gt;Second Item&lt;/li&gt;<br>                &lt;li class=&quot;child&quot;&gt;Third Item&lt;/li&gt;<br>             &lt;/ul&gt;<br>         &lt;/body&gt;<br>&lt;/html&gt;</pre><p>We can use the createElement() method to create a new &lt;li&gt; element in JavaScript code.</p><pre>const newList = document.createElement(&quot;li&quot;);</pre><p>Now, we can easily add some content to the newList using the textContent method;</p><pre>const newList = document.createElement(&quot;li&quot;);<br>newList.textContent = &quot;Fourth Item&quot;;<br>console.log(newList)</pre><p>The output would be “Fourth Item”.</p><p>Quite interesting, isn’t it? With this, we can easily add elements and text content into existing HTML code in just a few lines. We can now go ahead to insert this into the existing list in the HTML code as a fourth Item.</p><h3>Inserting Elements</h3><p>We have seen how we can select and create elements, now we can easily insert elements in the DOM.</p><p>We can easily do this using the append() or appendChild() method. For example, we would use one of these to insert a new list as the Fourth Item in the HTML code.</p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;DOM Manipulation&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>            &lt;ul class=&quot;parent&quot;&gt;<br>                &lt;li class=&quot;child&quot;&gt;First Item&lt;/li&gt;<br>               &lt;li class=&quot;child&quot;&gt;Second Item&lt;/li&gt;<br>                &lt;li class=&quot;child&quot;&gt;Third Item&lt;/li&gt;<br>             &lt;/ul&gt;<br>         &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const items = document.querySelector(&quot;ul&quot;)<br>const newList = document.createElement(&quot;li&quot;);<br>newList.textContent = &quot;Fourth Item&quot;;<br>items.appendChild(newList);</pre><p>In the preceding code, the ul element and stored in a variable items. Then we create a new li element using the createElement method, storing it in a variable newList. We easily add some content to it using the textElement method.</p><p>To add newList to items, we use the append method while passing newList as the parameter. The updated list would be updated to;</p><pre>First Item<br>Second Item<br>Third Item<br>Fourth Item</pre><h3>Removing and Replacing Elements</h3><p>Just as we can select and insert elements into the DOM, we can also easily remove elements from the DOM using the remove() method.</p><p>For example, let us remove the first item from the list with this method. We would first select the first li element using querySelector and store it in a variable firstItem.</p><pre>const firstItem = document.querySelector(&quot;li&quot;);<br>firstItem.remove();<br>document.querySelector(&quot;li&quot;);</pre><p>Using the remove() method, we deleted the first list from the HTML list, which would now be updated to:</p><pre>Second Item<br>Third Item</pre><p>In cases where we want to replace the element and not get rid of them, we can use the replaceWith() method.</p><pre>const newList = document.createElement(&quot;li&quot;);<br>newList.textContent = &quot;Fourth Item&quot;;<br>const firstItem = document.querySelector(&quot;li&quot;)<br>firstItem.replaceWith(newList);</pre><p>The list would be updated to:</p><pre>Fourth Item               <br>Second Item<br>Third Item</pre><h3>Cloning DOM Nodes</h3><p>We can clone a Node using the cloneNode() method. This would return a brand new node and keep the old node. It takes an optional argument which is a boolean argument that is, either true or false.</p><p>By default, it is set at false, and in this case, only the selected element is cloned without any nested element.</p><p><strong>COPY</strong></p><pre>&lt;html&gt;<br>          &lt;head&gt;<br>                &lt;title&gt;Cloning DOM Nodes&lt;/title&gt;<br>                &lt;script src=&quot;./app.js&quot; defer&gt;&lt;/script&gt;<br>          &lt;/head&gt;<br>          &lt;body&gt;<br>            &lt;ul class=&quot;parent&quot;&gt;<br>                &lt;li class=&quot;child&quot;&gt;First Item&lt;/li&gt;<br>               &lt;li class=&quot;child&quot;&gt;Second Item&lt;/li&gt;<br>                &lt;li class=&quot;child&quot;&gt;Third Item&lt;/li&gt;<br>             &lt;/ul&gt;<br>         &lt;/body&gt;<br>&lt;/html&gt;</pre><pre>const items = document.querySelector(&quot;ul&quot;);<br>const clone = items.cloneNode(false);<br>console.log(clone);</pre><p>The output would be</p><pre>&lt;ul class=&quot;parent&quot;&gt; &lt;/ul&gt;</pre><p>When the argument is true, all descendants of the selected element will be cloned.</p><pre>const items = document.querySelector(&quot;ul&quot;);<br>const clone = items.cloneNode(true);<br>console.log(clone);</pre><p>The output in the console would be:</p><pre> &lt;ul class=&quot;parent&quot;&gt;<br>                &lt;li class=&quot;child&quot;&gt;First Item&lt;/li&gt;<br>               &lt;li class=&quot;child&quot;&gt;Second Item&lt;/li&gt;<br>                &lt;li class=&quot;child&quot;&gt;Third Item&lt;/li&gt;<br>           &lt;/ul&gt;</pre><h3>-Akash Sheikh</h3><p>Jr. Software Engineer at Nitto Digital Services and Analytics Ltd.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77be5ff7f809" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>