<?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: Mohamed Yahia</title>
    <description>The latest articles on DEV Community by Mohamed Yahia (@itsmohamedyahia).</description>
    <link>https://dev.to/itsmohamedyahia</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%2F944275%2F49227333-93d3-43d6-b785-a7c6d740d83e.jpeg</url>
      <title>DEV Community: Mohamed Yahia</title>
      <link>https://dev.to/itsmohamedyahia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/itsmohamedyahia"/>
    <language>en</language>
    <item>
      <title>File permissions in unix-like OSs ft. ls stdout</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Fri, 22 Dec 2023 19:44:02 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/file-permissions-in-unix-like-oss-ft-ls-stdout-30ec</link>
      <guid>https://dev.to/itsmohamedyahia/file-permissions-in-unix-like-oss-ft-ls-stdout-30ec</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nuclearegg69@zenbook-f13:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
total 56
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 nuclearegg69 nuclearegg69    0 Oct 10 07:55 1
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 nuclearegg69 nuclearegg69    0 Oct 10 07:55 2
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 nuclearegg69 nuclearegg69    0 Oct 10 07:55 3
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 nuclearegg69 nuclearegg69   84 Oct  8 15:33 a
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 nuclearegg69 nuclearegg69   27 Oct  7 15:08 alphabet.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run the list command with long option, you are faced with some data at the beginning of each file. &lt;code&gt;-rw-r--r-- 1 nuclearegg69 nuclearegg69&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;what does this mean?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Lets begin with &lt;code&gt;-rw-r--r--&lt;/code&gt; (First Column)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;-&lt;/code&gt; means the object type, here it is a file, so it is denoted by &lt;code&gt;-&lt;/code&gt;, directories are denoted by &lt;code&gt;d&lt;/code&gt;, symbolic links are denoted by &lt;code&gt;l&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;r&lt;/code&gt; means the file can be read&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;w&lt;/code&gt; means the file can be written upon so it can be modified&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;-&lt;/code&gt; after &lt;code&gt;w&lt;/code&gt; means file cant be executed&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But &lt;code&gt;-&lt;/code&gt; at the beginning meant that the object is a file.&lt;/p&gt;

&lt;p&gt;Well, &lt;code&gt;-&lt;/code&gt; is used as a negative symbol and if you counted the number of characters at that string of characters, you will find them to be 10 characters.&lt;/p&gt;

&lt;p&gt;The first character is for the object type and i stated what character is used to represent each type. Then the rest are 9 characters which are divided into 3 groups of 3 characters.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first three characters represent the file permissions by the current user&lt;/li&gt;
&lt;li&gt;The second three characters represent the file permissions by the current user group&lt;/li&gt;
&lt;li&gt;The third three characters represent the file permissions for any user of the system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's break this out more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;the first 3 characters out of the 9 characters &lt;code&gt;rw-&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if there is no read, write or execute permissions, it would be denoted by &lt;code&gt;---&lt;/code&gt;. Now, we have &lt;code&gt;rw-&lt;/code&gt; which means we have read and write permissions for the current user but no execute permissions.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the second 3 characters are &lt;code&gt;r--&lt;/code&gt;. This means the current user group has read permissions but write or execute permissions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the third 3 characters are &lt;code&gt;r--&lt;/code&gt;. This means all other users have read only permissons.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and that's it for file permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Second column
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Hey, Mohamed, before you leave. what about the 1 after the 10 file permission characters?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Excellent question, 1 denotes the number of hard links to that file in disk.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hard links are essentially a pointer to that file. A pointer in the form of a file. So there can be two "apparent" "files" with different names in the same directory but when you edit one the other gets changed as if they are the same file. Well, indeed, they are the same file. When you do &lt;code&gt;ls&lt;/code&gt;, you get back a list of directory entries and not "files".&lt;/p&gt;

&lt;p&gt;Each directory entry is coupled with an inode number. The inode number identifies the inode. The inode is data structure or a table that contains metadata about that entry. That includes the name, size, number of hard links, modification time and more but more importantly it includes pointers that point to the data blocks in the disk storage that contains the entry data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nuclearegg69@zenbook-f13:~$ ls -i
 6115 1    6092 a              4833 colt-ex   6062 inNano3.txt     2344 testRen2
 6115 1a   4823 alphabet.txt   6091 echo      1281 inNanoRenamed   6060 unsorted.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;*Note that entry "1" and entry "1a" have the same inode number"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, what we actually refer to as files are actually just file names or hard links with an inode number. And we can create hard links by doing &lt;code&gt;ln 1 1a&lt;/code&gt; as i previously did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Third Column
&lt;/h2&gt;

&lt;p&gt;The third column in line is &lt;code&gt;nuclearegg69&lt;/code&gt;. This is the current username.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fourth Column
&lt;/h2&gt;

&lt;p&gt;The fourth column being &lt;code&gt;nuclearegg69&lt;/code&gt; is the current username group. And a group of users are just created to assign them similar permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rest of Columns
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fifth column is the file size in bytes&lt;/li&gt;
&lt;li&gt;Sixth column is the modification time&lt;/li&gt;
&lt;li&gt;And the last column is the file name.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>bash</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Quirks with 'value' attrib/prop on 'input' element/object</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Thu, 21 Dec 2023 12:34:09 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/quirks-with-value-attributeproperty-on-input-elementobject-3egm</link>
      <guid>https://dev.to/itsmohamedyahia/quirks-with-value-attributeproperty-on-input-elementobject-3egm</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input value='something'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--upFqu_6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ojimogqjx02vl3ssmwp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--upFqu_6a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ojimogqjx02vl3ssmwp.png" alt="Image description" width="319" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we change the user input (text on ui) to be 'something else', what happens to the attribute value in the html and what happens to the value property on the dom object representing that element?&lt;/p&gt;

&lt;p&gt;The property value will change but the attribute value wont change. WHY?&lt;/p&gt;

&lt;p&gt;Because if we wanted to reset the user input to the default value attrib value, we wont be able to since with each user input change the attribute value changes and thus the default value is lost&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wTI7S7dm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/namfbnlncccbhvpqwkfm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wTI7S7dm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/namfbnlncccbhvpqwkfm.png" alt="Image description" width="363" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kUCQ0ass--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8zy34ar2jyeq8wh2ore.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kUCQ0ass--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8zy34ar2jyeq8wh2ore.png" alt="Image description" width="697" height="56"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we changed the property value, it will change the user input on the ui but it wont change the attribute value for the same reasons.&lt;/p&gt;

&lt;p&gt;If we changed the attribute value, there are two behaviors.&lt;/p&gt;

&lt;p&gt;If the user input changed from the default attribute value even if we changed it and then wrote the default value back again so its based on change and not equality, then if we changed the attribute value it will not reflect either in the ui nor the dom object.&lt;/p&gt;

&lt;p&gt;The reason behind this is that we dont want to lose the user input.&lt;/p&gt;

&lt;p&gt;If the user input didnt change at all and we changed the attribute value, then it will reflect in the ui and correspondly in the dom object.&lt;/p&gt;

&lt;p&gt;The way to change the attribute value is by using 'setAttribute' method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;input.setAttribute('value', 'something else')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How to reset input to be default attribute value?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;input.value = input.getAttribute('value')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>CLOSURES!!</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Mon, 18 Dec 2023 17:59:39 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/closures-1bi4</link>
      <guid>https://dev.to/itsmohamedyahia/closures-1bi4</guid>
      <description>&lt;p&gt;A closure is a function with its outer function lexical scope/environment.&lt;/p&gt;

&lt;p&gt;What does 'lexical' mean?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;'Lexical' means relating to words, so the 'lexical scope of a function' is the scope related to the wording of that function or the definition of that function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;doSth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//some code&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;doSthFancy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// do sth fancy&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;doSthElse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;doSth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;doSthElse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 'lexical scope' of the function above &lt;code&gt;doSth&lt;/code&gt; is the global context since it is worded/defined in the global space, but the invocation scope is the doSthElse function space since it runs there.&lt;/p&gt;

&lt;p&gt;Now back to the closure definition.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A closure is a function lexical scope with its outer function lexical scope/environment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, what is the closure of doSth? its &lt;code&gt;doSth&lt;/code&gt; + &lt;code&gt;global scope&lt;/code&gt; (which contains doSthElse as a variable).&lt;/p&gt;

&lt;p&gt;Why we were able to run doSth from doSthElse? Because doSth is in the lexical scope of doSthElse (lexical scope of doSthElse is the global scope and doSth is defined there so it is available for doSthElse to use).&lt;/p&gt;

&lt;p&gt;BUT if we added &lt;code&gt;doSthFancy&lt;/code&gt;,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;doSthElse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;doSth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nf"&gt;doSthFancy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and tried to execute doSthElse, it would throw an error complaining that doSthFancy is not defined.&lt;/p&gt;

&lt;p&gt;So, why is a closure useful? JUST A DEFINITION!?&lt;/p&gt;

&lt;p&gt;Let's see.&lt;/p&gt;

&lt;p&gt;First: (which is the boring usecase)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;some variable&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;innerFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;innerFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 'some variable'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we ran outerFunction, 'some variable' is console logged but why? There is no &lt;code&gt;variable&lt;/code&gt; variable declared in the &lt;code&gt;innerFunction&lt;/code&gt;, how did &lt;code&gt;innerFunction&lt;/code&gt; get the value of variable from the &lt;code&gt;outerFunction&lt;/code&gt;? That is because functions have access to variables declared within its lexical scope which includes the &lt;code&gt;outerFunction&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;SO BORING YES, but watch this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;some variable&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;innerFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;variable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;innerFunction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outerFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nf"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOW, in the assignment of &lt;code&gt;someFunction&lt;/code&gt; to the &lt;code&gt;outerFunction&lt;/code&gt; call, the &lt;code&gt;innerFunction&lt;/code&gt; is returned AND it didnt run. Outer function got executed, finished executing, no longer there in the call stack, variable value is not there anymore sinced its gone.&lt;/p&gt;

&lt;p&gt;BUT then we run the innerFunction at &lt;code&gt;someFunction()&lt;/code&gt; where the invokation context now is the global space and there is no &lt;code&gt;variable&lt;/code&gt; variable there so the console log value should be undefined BUT THAT IS NOT THE CASE.&lt;/p&gt;

&lt;p&gt;The logged value is 'some variable' MAGIC? No, its closures baby. That function &lt;code&gt;someFunction&lt;/code&gt; gets the variables defined in its lexical scope when it is invoked to work with.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z2NB1E3n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i1qba36nc9xvci69tjyi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z2NB1E3n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i1qba36nc9xvci69tjyi.png" alt="Image description" width="560" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might be thinking now, that's interesting. You know what is more interesting? &lt;code&gt;You&lt;/code&gt;. Nah, I am joking. You are not that interesting or you are but you know what's more interesting? You're not falling for it again, huh. Ok, what's more interesting is that &lt;code&gt;someFunction&lt;/code&gt; doesnt only get its lexical scope but also its parent/outer function lexical scope, watch this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outerOuter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;something&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;something&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;something&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;outer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outerOuter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;outer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nf"&gt;inner&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//something&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lexical scope of the parent function is this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r0iRE1Nk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdeafo2k6m3fovzfx616.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r0iRE1Nk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdeafo2k6m3fovzfx616.png" alt="Image description" width="524" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and that's why 'something' was logged&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Example for closures
&lt;/h2&gt;

&lt;p&gt;Lets say we have some buttons and we want to run event handlers when they are clicked&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;button2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;button3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;document.body.appendChild&lt;/code&gt; is repeated in these 3 handlers, I dont like that, the only thing changing is the element name. so what can we do?&lt;/p&gt;

&lt;p&gt;Well the first guess is that we would make a function that accepts that dynamic/changing part as a parameter and it would return that repeated logic with the element name that it got passed&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;appendEl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spectactular. Now we only have to pass that function as the event handler of the click event&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;appendEl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is that right? Nope, because we are not passing a function, we are invoking it and what we are actually passing is the evaluation of the appendEl call which is the return value of it which is undefined. so how could we solve this?&lt;/p&gt;

&lt;p&gt;an easy way would be this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;appendEl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To just add it as the function body of another function&lt;/p&gt;

&lt;p&gt;Another solution would be to use bind (and it is more useful in some cases where we need to assign the &lt;code&gt;button&lt;/code&gt; object to &lt;code&gt;this&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;appendEl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Third solution which I consider the cleanist is by making appendEl return a function containing the logic.&lt;/p&gt;

&lt;p&gt;** ALERT: HIGHER ORDER FUNCTION INCOMING **&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;appendEl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;appendEl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we could just do this. Now &lt;code&gt;appendEl&lt;/code&gt; will return a function and when it runs it will need the el variable which will be present for the inner function to use even though &lt;code&gt;appendEl&lt;/code&gt; ran and finished execution and that was made possible by CLOSURES.&lt;/p&gt;




&lt;p&gt;That is the CLOSURE of this article (see what I did there!), hope you enjoyed it, understood it, and sEe yOu iN tHe nExT oNe.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>HTML Collection vs NodeList</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Sun, 17 Dec 2023 11:18:49 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/html-collection-vs-nodelist-3ej8</link>
      <guid>https://dev.to/itsmohamedyahia/html-collection-vs-nodelist-3ej8</guid>
      <description>&lt;p&gt;Both are array-like objects but they differ in some areas&lt;/p&gt;

&lt;h5&gt;
  
  
  HTML Collection
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;is a collection of element nodes&lt;/li&gt;
&lt;li&gt;is returned by 'getElementsByClassName' and 'getElementsByTagName'&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Nodelist
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;contains all types of nodes: element nodes, text nodes, etc&lt;/li&gt;
&lt;li&gt;is returned by 'querySelectorAll'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;====&lt;/p&gt;

&lt;p&gt;NodeList returned by querySelectorAll is static. Static means that it doesnt get updated if more items that match the query are added, removed, modified. It doesnt mean that updating properties of an item inside a nodelist wont be reflected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"luck"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;easy mate&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"luck"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;easy bait&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"luck"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;easy late&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pEls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pEls&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {p, p , p}&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pEls&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {p, p , p}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so it didnt get added to the node list but if we did the same but used &lt;code&gt;getElementsByTagName&lt;/code&gt; it would get reflected and we would see the fourth p added to the html collection&lt;/p&gt;

</description>
    </item>
    <item>
      <title>window object and the DOM</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Thu, 14 Dec 2023 10:47:02 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/window-object-and-the-dom-451e</link>
      <guid>https://dev.to/itsmohamedyahia/window-object-and-the-dom-451e</guid>
      <description>&lt;p&gt;When we query an element in js using &lt;code&gt;document.querySelector&lt;/code&gt; syntax. We might would want to stop a bit and think about what we wrote &lt;code&gt;document.querySelector&lt;/code&gt; looks like the syntax we use for properties on a object where the name before the dot (.) represents the name of the object and the name after the dot represent a property or method on that object. since &lt;code&gt;querySelector&lt;/code&gt; is a function, we can say that querySelector is a method of the object document.&lt;/p&gt;

&lt;p&gt;But where did that document object come from, we didnt create it. That object is created by the browser so that we could those functions that we also didnt create like querySelector.&lt;/p&gt;

&lt;p&gt;You might hear a buzzword called the DOM. What does DOM stand for? DOM stands for document object model. The model of the document object. So now, what i understand that it has sth to do with that document object we were talking about earlier. Or they are kind of the same thing ..except for the 'model' part. Lets understand what the document object contains and we will come back the model part.&lt;/p&gt;

&lt;p&gt;If we want to know what the document object contains, we might go to the console and write document and enter and we will get the html of the page&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BJexxgx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7hpwcjb7fos207n7cb2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BJexxgx7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7hpwcjb7fos207n7cb2.png" alt="Image description" width="800" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;SO now, I am confused is the document object the html code of the html document we wrote. But if that so, how is it an object, html is not javascript. Well that's because that's what the browser dev tools wants you to see. We know that an object contains key value pairs. &lt;/p&gt;

&lt;p&gt;To be able to see the real document object, we write &lt;code&gt;console.dir(document)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8xzPJ3B3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhx6ky0tqpobgjwgna9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8xzPJ3B3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhx6ky0tqpobgjwgna9k.png" alt="Image description" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we scroll down, we will find a &lt;code&gt;children&lt;/code&gt; property that has a value of type HTMLCollection.&lt;/p&gt;

&lt;p&gt;HTML Collections are array-like objects. At its first index 0, we have some properties including an outerHTML, localName, nodeName all indicating that it is an object that represents the HTML element and if we scroll down we will find another children property which includes the head and body elements at index 0, 1 respectively.&lt;/p&gt;

&lt;p&gt;This informs us that the document object is a representation of the html tree and the document object in itself the way it is designed through the children properties (@&lt;a class="mentioned-user" href="https://dev.to/looks"&gt;@looks&lt;/a&gt; like) a tree and that why it is called the document object model because it is modeling the html code.&lt;/p&gt;

&lt;p&gt;When we use &lt;code&gt;querySelector&lt;/code&gt; what it actually does is it searches the document object for the object that represents the element we are looking for and that object has properties attached to it and we can change those properties like 'element.backgroundColor' and set them to be something else just like we change properties on simple objects.&lt;/p&gt;

&lt;p&gt;There is also another object that provided to us by the browser called the 'window' object. It also has some other properties like height and width of the current window/tab and other methods and actually one of its properties is the document object. SO the document object is a subset of the window object and that makes sense since the document object, which is a representation of the html code, is part of the window.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Execute commands on 'find' output ft. -exec and xargs</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Wed, 13 Dec 2023 19:43:30 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/execute-commands-on-find-output-ft-exec-and-xargs-2a0a</link>
      <guid>https://dev.to/itsmohamedyahia/execute-commands-on-find-output-ft-exec-and-xargs-2a0a</guid>
      <description>&lt;h1&gt;
  
  
  How to run commands on files found
&lt;/h1&gt;

&lt;p&gt;If I want to delete any log files in a directory and log files in this directory have common substring "log" in their name, we could do it all in one command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nuclearegg69@zenbook-f13:~$ ls
1   2  a             b  colt-ex  empty  hello2   inNano3.txt    inNanoSymlink  testRen2      unsortedNums.txt  world2
1a  3  alphabet.txt  c  echo     hello  inNano3  inNanoRenamed  testRen        unsorted.txt  world
nuclearegg69@zenbook-f13:~$ find ~ -name "*hello*" -exec rm -r '{}' ';'
nuclearegg69@zenbook-f13:~$ ls
1   2  a             b  colt-ex  empty    inNano3.txt    inNanoSymlink  testRen2      unsortedNums.txt  world2
1a  3  alphabet.txt  c  echo     inNano3  inNanoRenamed  testRen        unsorted.txt  world
nuclearegg69@zenbook-f13:~$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nuclearegg69@zenbook-f13:~$ ls
1   2  a             b  colt-ex  empty  hello2   inNano3.txt    inNanoSymlink  testRen2      unsortedNums.txt  world2
1a  3  alphabet.txt  c  echo     hello  inNano3  inNanoRenamed  testRen        unsorted.txt  world
nuclearegg69@zenbook-f13:~$ find . -name "*hello*" | xargs rm -r
nuclearegg69@zenbook-f13:~$ ls
1   2  a             b  colt-ex  empty    inNano3.txt    inNanoSymlink  testRen2      unsortedNums.txt  world2
1a  3  alphabet.txt  c  echo     inNano3  inNanoRenamed  testRen        unsorted.txt  world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break those commands apart starting with the first one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;find&lt;/code&gt;: used to find objects (files, dirs, links) &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;~&lt;/code&gt; : in home directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-name&lt;/code&gt;: with a name of &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"*hello*"&lt;/code&gt;: containing substring hello (i.e. with zero or more characters before 'hello' and zero or more after)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-exec&lt;/code&gt;: execute following operation/command on every record found&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rm -r&lt;/code&gt;: delete recursively (so dir and all dirs and files nested within it)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;'{}'&lt;/code&gt; placeholder for current file/dir (so rm -r '{}' = delete current file/dir and it will run for every file/dir found) &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;';'&lt;/code&gt; : indicate the end of the rm command and is passed as a parameter to dir to not confuse the bash that it ends the whole find command&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;'{}'&lt;/code&gt; since this is a placeholder for current file name, it provides a convenient way for renaming files&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;find . -type f -exec mv '{}' '{}_new' ';'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This adds a substring &lt;code&gt;_new&lt;/code&gt; at the end of each file name&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;xargs&lt;/code&gt;: the pipe passes the list of files found to xargs standard input and xargs runs the command following it on each file, passing the file as an argument &lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>GIT RESET</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Mon, 11 Dec 2023 23:57:59 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/git-reset-jko</link>
      <guid>https://dev.to/itsmohamedyahia/git-reset-jko</guid>
      <description>&lt;h2&gt;
  
  
  Usecase
&lt;/h2&gt;

&lt;p&gt;My most common usecase for git reset is when i stage changes by mistake. Maybe i make some changes that involve multiple things and i want to divide them into seperate commits. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LgLuQKVp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l815s5fz02qfnn8ybia6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LgLuQKVp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l815s5fz02qfnn8ybia6.png" alt="Image description" width="800" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you add them, git tells you this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x1djK3bq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6wkdrwhq27ebxqi220b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x1djK3bq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6wkdrwhq27ebxqi220b.png" alt="Image description" width="745" height="210"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use "git restore --staged &amp;lt;file&amp;gt;..." to unstage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;since you know &lt;code&gt;.&lt;/code&gt; denotes the whole directory, you try &lt;code&gt;git restore --staged .&lt;/code&gt; and it unstages the changes. Here comes &lt;code&gt;reset&lt;/code&gt; with its shorter syntax, just &lt;code&gt;git reset&lt;/code&gt; and voila your changes are gone. &lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git reset&lt;/code&gt; is mainly used to undo commits.&lt;br&gt;
&lt;code&gt;git reset &amp;lt;commit hash&amp;gt;&lt;/code&gt; and it will delete all commits up until that commit and most importantly KEEP THE CHANGES or to be most specific move the changes to the working directory.&lt;/p&gt;

&lt;p&gt;That's why git reset without providing a commit, moves changes from the staging area to the working directory &lt;/p&gt;

&lt;p&gt;&lt;code&gt;git reset --hard&lt;/code&gt; deletes the changes so if you run this command bare it will delete the working directory and the staging area GONE but UNTRACKED FILES ARE NOT AFFECTED. &lt;/p&gt;

&lt;p&gt;This behavior for untracked files is the same with any git reset command, it's not specific to the &lt;code&gt;hard&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git reset --hard &amp;lt;commit hash&amp;gt;&lt;/code&gt; will delete changes up to that commit.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>CRLF — The line break character</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Mon, 11 Dec 2023 20:54:27 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/crlf-line-breaks-2dng</link>
      <guid>https://dev.to/itsmohamedyahia/crlf-line-breaks-2dng</guid>
      <description>&lt;h2&gt;
  
  
  Usecase
&lt;/h2&gt;

&lt;p&gt;Just yesterday, after i committed my lovely work on windows through vscode source control feature, I did a &lt;code&gt;git status&lt;/code&gt; through wsl and then I find multiple files that are modified. So they are modified files in wsl terminal but not on powershell, not on git bash and certainly not on vscode. &lt;/p&gt;

&lt;p&gt;I did a &lt;code&gt;git diff&lt;/code&gt; to investigate the issue and i find that all the lines in all files are highlighted in both versions except that they are the same. So why was git telling me there are changes when there was not, I wondered. &lt;/p&gt;

&lt;p&gt;I investigated the issue furthur through google and i found that the issue lies within the line break character which differs in windows from unix/unix-like systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Line breaks (windows vs unix)
&lt;/h2&gt;

&lt;p&gt;In unix, the line break character is the linefeed character &lt;code&gt;LF&lt;/code&gt; but in windows it is both a carriage-return &lt;code&gt;CR&lt;/code&gt; and a linefeed character, hence &lt;code&gt;CRLF&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;By default, git commits whatever line character is in the text but when you turn on &lt;code&gt;core.autocrlf&lt;/code&gt; in the repo or globally by &lt;code&gt;$ git config --global core.autocrlf true&lt;/code&gt; what git does, is it will convert LF characters to CRLF when viewed on windows but it will convert CRLF to LF when you commit code. So the repo will have LF characters. &lt;/p&gt;

&lt;p&gt;This feature should always be turned on if you are working on windows. &lt;/p&gt;

&lt;p&gt;If you are on linux, you could do &lt;code&gt;$ git config --global core.autocrlf input&lt;/code&gt; this will convert any CRLF characters to LF but not the other way around. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>git</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>npm projects</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Mon, 16 Oct 2023 18:56:50 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/npm-projects-4o7a</link>
      <guid>https://dev.to/itsmohamedyahia/npm-projects-4o7a</guid>
      <description>&lt;p&gt;To start an npm project, you can run &lt;code&gt;npm init&lt;/code&gt; in the directory where you want to initiate the project. &lt;/p&gt;

&lt;p&gt;You will be prompted with some prompts about the name of the project and some other stuff that you can just skip by pressing &lt;code&gt;enter&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;After that a &lt;code&gt;package.json&lt;/code&gt; file will be created. It will in a &lt;code&gt;json&lt;/code&gt; format as can be interpretted from the file extension.&lt;/p&gt;

&lt;p&gt;JSON is a text-based format for representing JS Objects. JSON stands for Javascript Object Notation. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhpg5q9gzmensxsv1y1ij.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhpg5q9gzmensxsv1y1ij.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is the default content of the file. The two curly braces and what's inside them is a JSON object literal. &lt;/p&gt;

&lt;h4&gt;
  
  
  Why literal or what does literal mean?
&lt;/h4&gt;

&lt;p&gt;Me too have wondered what is the meaning of literal that is shoved between text while the text itself makes sense without it &lt;code&gt;JSON object&lt;/code&gt; is understandable without the literal in the end.&lt;br&gt;&lt;br&gt;
Also, you might have heard about the literal syntax of declaring objects in javascript or the string literal. &lt;/p&gt;

&lt;p&gt;Literal is a notation (way of writing) for representing values. It is the "literal" notation of representing values. And literal here means the same meaning we know it for i.e. literally.&lt;br&gt;
Lets make it more clear.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let a = "boboddy"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;a is a string.&lt;br&gt;
"boboddy" is also a string.&lt;/p&gt;

&lt;p&gt;What is the difference between the two.&lt;/p&gt;

&lt;p&gt;One is a variable representing the string, the other is the "literal" way of representing the string.&lt;/p&gt;

&lt;p&gt;SO variables and constants cant be string literals or any value literal.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

let stringVar = String("something")


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

&lt;/div&gt;

&lt;p&gt;so &lt;code&gt;String("something")&lt;/code&gt; here is a value right? and it is a string because the string method will return a string as an output (it will get stored to stringVar but we are not talking about the variable here, we are talking about &lt;code&gt;String("something")&lt;/code&gt; as a value. It is a string but it is not a &lt;code&gt;string literal&lt;/code&gt; because it is not a literal string notation, the literal string notation is "something")&lt;/p&gt;

&lt;p&gt;and the same goes for the other kind of values.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;5&lt;/code&gt; is an integer literal but &lt;code&gt;2 + 3&lt;/code&gt; is not. Neither is &lt;code&gt;Number("5")&lt;/code&gt;. They are integers (in the sense that their &lt;code&gt;2 +3&lt;/code&gt; expression will evaluate to &lt;code&gt;5&lt;/code&gt; and the same goes for the other but they are not integer literals)&lt;/p&gt;

&lt;p&gt;You would often hear about the literal syntax of declaring an object. It is like that:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

let car = {
    model: "BMW",
    year: 2012
}



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

&lt;/div&gt;

&lt;p&gt;because those curly braces and the way of writing the key value pairs is the literal syntax.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

let car = new Object();
car.model = "BMW"
car.year = 2012



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

&lt;/div&gt;

&lt;p&gt;That is another way of declaring an object but it is not the literal way.&lt;/p&gt;

&lt;p&gt;I hope this is clear now.&lt;/p&gt;




&lt;p&gt;Ok, lets go back. Where were we? Yes, JSON Objects. Ok, so you can see a JSON object with key value pairs. &lt;br&gt;
The &lt;code&gt;scripts&lt;/code&gt; key contains a value of an object and this object consists of other key-value pairs. the default one we find is "test" but we can add more.&lt;br&gt;
Every key we add to the &lt;code&gt;scripts&lt;/code&gt; object is a script name and the value would the script itself (the script is a command or series of commands)&lt;/p&gt;

&lt;p&gt;The first default script is &lt;code&gt;test&lt;/code&gt; and when run it runs this line of code &lt;code&gt;echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So it will echo to the terminal "Error: no test specified" but not only that it will also run another command of &lt;code&gt;exit 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Scripts when run successfully exit with a code status of 0. 0 indicates success. In this case, yes, &lt;code&gt;echo&lt;/code&gt; did run successfully but the script as a whole is a test script. we didnt run any tests, so it would be logical to assume that the script has failed (technically it didnt yes). In that case, we want to change the exit status to a number that indicates failure. Any number other than zero indicates failure. So they choose 1 as the exit status.&lt;br&gt;
Note that line of code is just a placeholder for the actual test scripts we might have and we would like to replace this line with. &lt;/p&gt;

&lt;p&gt;Now, if your project is dependent upon a library like react or a framework, mostly you would find a &lt;code&gt;dev&lt;/code&gt; key with some command. When you &lt;code&gt;npm run dev&lt;/code&gt;, the app is running on a local server and you can make a request to the server through your browser in which the server responds with the  &lt;code&gt;index.html&lt;/code&gt; file. &lt;/p&gt;

&lt;p&gt;Since we have learned earlier how an npm project is created and how can we manipulate the package.json file, and I told you when the &lt;code&gt;test&lt;/code&gt; script runs it does blah blah blah but we didnt learn how to run it. &lt;/p&gt;

&lt;p&gt;Well, to run it, you open the terminal (VSCode Integrated Terminal) or any terminal program at the project directory and run &lt;code&gt;npm run ScriptNameInPackage.jsonFileWeWantToRun&lt;/code&gt; so in our case &lt;code&gt;npm run test&lt;/code&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

PS D:\Teach\BLOGS\NPM&amp;gt; npm run test

&amp;gt; npm@1.0.0 test
&amp;gt; echo "Error: no test specified" &amp;amp;&amp;amp; exit 1

"Error: no test specified" 


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

&lt;/div&gt;

&lt;p&gt;We could also do &lt;code&gt;npm test&lt;/code&gt; and the script would run but that's for some special script names only like &lt;code&gt;test&lt;/code&gt; and &lt;code&gt;start&lt;/code&gt; (If we added a start script, it would run with &lt;code&gt;npm start&lt;/code&gt; as well as &lt;code&gt;npm run start&lt;/code&gt;). But for any other custom names we do, we have to run them using &lt;code&gt;npm run scriptName&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, why does a server spin up serving our web app when we do &lt;code&gt;npm run dev&lt;/code&gt; in most web app projects using a library or framework?&lt;/p&gt;

&lt;p&gt;Because the dev key is configured to a script that script will run a program/dependency (called dependency since our app depends on it to run) which will bundle the app and transform the code of the library or the framework into vanilla js along with html,css. This dependency might be vite or webpack or another program. &lt;/p&gt;

&lt;p&gt;My focus here is that &lt;code&gt;npm run dev&lt;/code&gt; has nothing to do with those frameworks/libraries. You could create an empty directory, run &lt;code&gt;npm init&lt;/code&gt; to initialize (hence init) an npm project, add an html file and add a &lt;code&gt;dev&lt;/code&gt; key yourself whose value is &lt;code&gt;live-server&lt;/code&gt;. live server is a program that spins up a local server which will serve your app. You have probably used it as an extension in vscode but you can also install it globally on your system by running &lt;code&gt;npm i -g live-server&lt;/code&gt;. After you have installed it, you can run &lt;code&gt;npm run dev&lt;/code&gt; in your directory and voila the html file is open in your browser. You can go back and add some text to the html file to confirm that it is indeed working. &lt;/p&gt;

&lt;p&gt;Just one more thing that is intuitive but the file is called package because its main purpose is to keep a list of all the packages (hence package.json) aka dependencies aka programs that your app needs to run. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29ozemgvgb8qzff8hxic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29ozemgvgb8qzff8hxic.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so in another key called &lt;code&gt;dependencies&lt;/code&gt; it will store an object of the dependencies and the allowed versions so &lt;code&gt;^11.11.0&lt;/code&gt; allows running newer minor verions so &lt;code&gt;11.12.0&lt;/code&gt; is acceptable (middle or second number is the minor version, first is the major and the third i.e 0 in this case is for patch versions) &lt;br&gt;
&lt;em&gt;Read more about semantic versioning to get a clear idea of how versioning works&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;devDependencies is for dependencies that are used in the development environment for the development process but we dont need in production (also shorted prod).&lt;/p&gt;




&lt;p&gt;And that concludes it. Hope you have enjoyed the read. If it wont bother you, leave a like or comment and share your thoughts.&lt;/p&gt;

</description>
      <category>npm</category>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>what does "literal" mean?? string literal? object literal? literal syntax???</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Mon, 16 Oct 2023 18:50:40 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/what-does-literal-mean-string-literal-object-literal-literal-syntax-3k08</link>
      <guid>https://dev.to/itsmohamedyahia/what-does-literal-mean-string-literal-object-literal-literal-syntax-3k08</guid>
      <description>&lt;p&gt;Me too have wondered what is the meaning of literal that is shoved between text while the text itself makes sense. String literal they say, and I am wondering why not just say "string". Literal syntax of declaring objects !!&lt;/p&gt;

&lt;p&gt;Okay, Okay, enough talk, more action (or technically... more talk).&lt;/p&gt;

&lt;p&gt;Literal is a notation (way of writing) for representing values. It is the "literal" notation of representing values. And literal here means the same meaning we know it for i.e. literally.&lt;br&gt;
Lets make it more clear.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let a = "boboddy"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;a is a string.&lt;br&gt;
"boboddy" is also a string.&lt;/p&gt;

&lt;p&gt;What is the difference between the two.&lt;/p&gt;

&lt;p&gt;One is a variable representing the string, the other is the "literal" way of representing the string.&lt;/p&gt;

&lt;p&gt;SO variables and constants cant be string literals or any value literal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let stringVar = String("something")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so &lt;code&gt;String("something")&lt;/code&gt; here is a value right? and it is a string because the string method will return a string as an output (it will get stored to stringVar but we are not talking about the variable here, we are talking about &lt;code&gt;String("something")&lt;/code&gt; as a value. It is a string but it is not a &lt;code&gt;string literal&lt;/code&gt; because it is not a literal string notation, the literal string notation is "something")&lt;/p&gt;

&lt;p&gt;and the same goes for the other kind of values.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;5&lt;/code&gt; is an integer literal but &lt;code&gt;2 + 3&lt;/code&gt; is not. Neither is &lt;code&gt;Number("5")&lt;/code&gt;. They are integers (in the sense that their &lt;code&gt;2 +3&lt;/code&gt; expression will evaluate to &lt;code&gt;5&lt;/code&gt; and the same goes for the other but they are not integer literals)&lt;/p&gt;

&lt;p&gt;You would often hear about the literal syntax of declaring an object. It is like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let car = {
    model: "BMW",
    year: 2012
}

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

&lt;/div&gt;



&lt;p&gt;because those curly braces and the way of writing the key value pairs is the literal syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let car = new Object();
car.model = "BMW"
car.year = 2012

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

&lt;/div&gt;



&lt;p&gt;That is another way of declaring an object but it is not the literal way.&lt;/p&gt;

&lt;p&gt;I hope this is clear now.&lt;/p&gt;




&lt;p&gt;Thank you for taking the time to read this article. If you found it helpful, leave a like or a comment. If you have any questions, feel free to ask them down below. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Expansion and Substitution in Unix-like Operating Systems</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Thu, 12 Oct 2023 10:14:55 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/expansion-and-substitution-in-unix-like-shells-35n1</link>
      <guid>https://dev.to/itsmohamedyahia/expansion-and-substitution-in-unix-like-shells-35n1</guid>
      <description>&lt;h2&gt;
  
  
  Pathname expansion
&lt;/h2&gt;

&lt;p&gt;expanding a pathname, how do we do that?&lt;/p&gt;

&lt;p&gt;if we do &lt;code&gt;echo 2 * 3&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nuclearegg69@zenbook-f13:~/testRen$ echo 2 * 3
2 a apple b banana c cactus inNano2Ren test2 3

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

&lt;/div&gt;



&lt;p&gt;I am presented with those what appears to be file names of current directory, all of them, the 2 and 3 are present at both ends but the asterisk * got replaced/expanded into those file names&lt;/p&gt;

&lt;p&gt;This one of the wildcard characters that we can use for expansion. The following list contain some more: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;* asterisk: 

&lt;ul&gt;
&lt;li&gt;it matches 0 or more characters&lt;/li&gt;
&lt;li&gt;ex: *.txt matches file.txt and 0.txt and .txt&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;? question mark: 

&lt;ul&gt;
&lt;li&gt;matches any one character&lt;/li&gt;
&lt;li&gt;ex: blue?.txt matches blue1.txt and bluez.txt but doenst match blue12.txt&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;[] square brackets or range wilcards:

&lt;ul&gt;
&lt;li&gt;they match a range of characters inside them&lt;/li&gt;
&lt;li&gt;ex: [rbc]at matches rat, bat or cat&lt;/li&gt;
&lt;li&gt;ex: [a-h]* matches any name that starts with a to h (case sensitivity matters so only small letters a to h) &lt;/li&gt;
&lt;li&gt;ex: [0-9]* matches any name that starts with a number&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Arithmetic expansion
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nuclearegg69@zenbook-f13:~$ echo $((5+5))
10

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

&lt;/div&gt;



&lt;p&gt;syntax: &lt;code&gt;$((arithmetic_expression))&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Command substitution
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nuclearegg69@zenbook-f13:~/testRen$ echo today is $(date)
today is Thu Oct 12 11:50:06 +03 2023
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;syntax: &lt;code&gt;$(command)&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Changing-behavior Quotes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nuclearegg69@zenbook-f13:~/testRen$ a=5
nuclearegg69@zenbook-f13:~/testRen$ echo $a
5
nuclearegg69@zenbook-f13:~/testRen$ echo "$a"
5
nuclearegg69@zenbook-f13:~/testRen$ echo "\$a"
$a
nuclearegg69@zenbook-f13:~/testRen$ echo '$a'
$a
nuclearegg69@zenbook-f13:~/testRen$ echo "$((a+4))"
9
nuclearegg69@zenbook-f13:~/testRen$ echo '$((a+4))'
$((a+4))
nuclearegg69@zenbook-f13:~/testRen$ echo 1..9
1..9
nuclearegg69@zenbook-f13:~/testRen$ echo {1..9}
1 2 3 4 5 6 7 8 9
nuclearegg69@zenbook-f13:~/testRen$ echo "{1..9}"
{1..9}
nuclearegg69@zenbook-f13:~/testRen$ echo ~
/home/nuclearegg69
nuclearegg69@zenbook-f13:~/testRen$ echo "~"
~
nuclearegg69@zenbook-f13:~/testRen$ echo '~'
~
nuclearegg69@zenbook-f13:~/testRen$ echo *
a apple b banana c cactus inNano2Ren test2
nuclearegg69@zenbook-f13:~/testRen$ echo '*'
*
nuclearegg69@zenbook-f13:~/testRen$ echo "*"
*
nuclearegg69@zenbook-f13:~/testRen$ echo "`ls`"
a
apple
b
banana
c
cactus
inNano2Ren
test2
nuclearegg69@zenbook-f13:~/testRen$ echo '`ls`'
`ls`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Based on the above commands, we can deduce that:&lt;/p&gt;

&lt;p&gt;1- double quotes: they disable all substitutions except those that involve a $ (dollar sign), \ (backslash), ` (backtick)&lt;/p&gt;

&lt;p&gt;2- single quotes: disable all substitutions.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>linux</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>All About JS Functions</title>
      <dc:creator>Mohamed Yahia</dc:creator>
      <pubDate>Wed, 11 Oct 2023 22:32:00 +0000</pubDate>
      <link>https://dev.to/itsmohamedyahia/all-about-functions-4a8d</link>
      <guid>https://dev.to/itsmohamedyahia/all-about-functions-4a8d</guid>
      <description>&lt;p&gt;&lt;em&gt;Not All, I have tricked you.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  typeof functions
&lt;/h2&gt;

&lt;p&gt;When you do &lt;code&gt;typeof &amp;lt;someFunction&amp;gt;&lt;/code&gt;, you get back 'function'. But, you might have heard that functions are objects??&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UlSAADXM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://upload.wikimedia.org/wikipedia/commons/0/0a/Typeof_functions_vs_console.dir_functions.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UlSAADXM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://upload.wikimedia.org/wikipedia/commons/0/0a/Typeof_functions_vs_console.dir_functions.png" alt="image" width="472" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, they are indeed objects, if you do console.dir() on a function, you will get an object with key value pairs and a prototype, the reason why you get 'function' when you pass it as an operand to typeof operator is because that is the way typeof is configured&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UZ_WKtj---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://upload.wikimedia.org/wikipedia/commons/4/42/Typeof_operator_results_from_ecma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UZ_WKtj---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://upload.wikimedia.org/wikipedia/commons/4/42/Typeof_operator_results_from_ecma.png" alt="image" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the image, objects which are callable return 'function'&lt;/p&gt;

&lt;h2&gt;
  
  
  function declarations vs function expressions
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//function declaration

function doSth() {
  //do sth
}


// function expression

const doSth = ()=&amp;gt; {
  // do sth
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  what are the implications of using either one of those??
&lt;/h4&gt;

&lt;p&gt;Functions and variables are hoisted (as if they are lifted up at the top of the code, metaphorically). But only the declaration is hoisted, this has a very important implications, variables will be declared but they will not be assigned a value (another term of assigning a value is initializating). That means if you call functions before they are declared, you can but if you try to access a variable before it is declared, you will get&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dI67GfEQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://upload.wikimedia.org/wikipedia/commons/c/c3/Hoisting_variables.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dI67GfEQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://upload.wikimedia.org/wikipedia/commons/c/c3/Hoisting_variables.png" alt="image" width="760" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;BONUS for English Non-native Speakers: hoisting actually means to lift sth up, it is not a word that is javascript-specific.&lt;/p&gt;

&lt;p&gt;The image below shows a hoist (lifter)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pBL2V2zP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://alimak.com/nl/wp-content/uploads/sites/24/2020/11/Hero-image.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pBL2V2zP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://alimak.com/nl/wp-content/uploads/sites/24/2020/11/Hero-image.jpg" alt="image" width="666" height="592"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, what are the implications again??&lt;/p&gt;

&lt;p&gt;You can declare functions which are in the form of function declarations AFTER they are called but you can't with function expressions because they are variables and they are assigned a function (which is also a value or variable)&lt;/p&gt;

&lt;p&gt;So you can do this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;doSth()

function doSth() {
  //do sth
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But not this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;doSth()

const doSth = ()=&amp;gt; {
//do sth
}

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  What happens if I call a function that expects two arguments with one argument, will the function run??
&lt;/h4&gt;

&lt;p&gt;Yes, it will run. The second argument will be undefined.&lt;/p&gt;

&lt;h4&gt;
  
  
  If I want to call a function but I dont know the number of arguments beforehand, what should I do?
&lt;/h4&gt;

&lt;p&gt;There are two ways to do it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ES5 way&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 getSum() {
  let sum = 0;
  for (const number of arguments) {
    sum += number;
  }
  return sum;
}

console.log(getSum(1, 2, 3, 4));

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;WHAT IS "ARGUMENTS", WHERE DID THAT ARRAY COME FROM??&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That is actually an array-like object, not an array. Array-like objects are objects that have a length property and have indices as properties which have array-like items as values&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qtovqKuD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://upload.wikimedia.org/wikipedia/commons/f/fc/Array-like_object_has_a_symbol.iterator_method.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qtovqKuD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://upload.wikimedia.org/wikipedia/commons/f/fc/Array-like_object_has_a_symbol.iterator_method.png" alt="image" width="800" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Array-like objects are &lt;code&gt;iterables&lt;/code&gt; in js and that means we can iterate over them using &lt;code&gt;for..of&lt;/code&gt; or &lt;code&gt;for i = 0&lt;/code&gt; loops but not &lt;code&gt;forEach&lt;/code&gt; because that is an array method.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;arguments&lt;/code&gt; is a reserved keyword or variable and its value is an array-like object of all arguments you called the function with&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ES6 way&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With es6, we have a new operator called the rest operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getSum(...numbers) {
  let sum = 0;
  for (const number of numbers) {
    sum += number;
  }
  return sum;
}
console.log(getSum(1, 2, 3, 4));

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

&lt;/div&gt;



&lt;p&gt;The rest operator simply combines values passed into an array. The naming behind comes from that we can do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getSum(firstNumber, ...numbers) {
  let sum = 0;
  for (const number of numbers) {
    sum += number;
  }
  return sum;
}

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

&lt;/div&gt;



&lt;p&gt;Now the first argument passed will be assigned to firstNumber and &lt;strong&gt;''the rest''&lt;/strong&gt; of the arguments will form an array called &lt;code&gt;numbers&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;That's the end of this article. Thanks for reading. I hope I have added something new to your arsenal of knowledge. If you liked the article, a quick thumps up or a comment would be appreciated and would help me continue sharing information. See you in the next one!&lt;/em&gt;&lt;/p&gt;

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