<?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 The Coding Bear on Medium]]></title>
        <description><![CDATA[Stories by The Coding Bear on Medium]]></description>
        <link>https://medium.com/@yelloveprogrammer?source=rss-7ad7abd87578------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pisRgoI6jYQMyMfTRvWJdQ.png</url>
            <title>Stories by The Coding Bear on Medium</title>
            <link>https://medium.com/@yelloveprogrammer?source=rss-7ad7abd87578------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 20:53:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yelloveprogrammer/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[Data Structures and Algorithms(DSA) using JavaScript — Big O Notation]]></title>
            <link>https://medium.com/@yelloveprogrammer/data-structures-and-algorithms-dsa-using-javascript-big-o-notation-9f46d7deb81c?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f46d7deb81c</guid>
            <category><![CDATA[big-o]]></category>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 08:20:24 GMT</pubDate>
            <atom:updated>2020-06-04T10:19:07.096Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Structures and Algorithms(DSA) using JavaScript — Big O Notation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kwHdjALOn5MwazOc" /><figcaption>Photo by <a href="https://unsplash.com/@yongchuan?utm_source=medium&amp;utm_medium=referral">Yong Chuan Tan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Prerequisites</h3><ul><li>JavaScript</li></ul><h3>Objectives</h3><ul><li>Motivate the need for something like Big O Notation</li><li>Describe what Big O Notation is</li><li>Simplify Big O Expressions</li><li>Define “time complexity” and “space complexity”</li><li>Evaluate the time complexity and space complexity of different algorithms using Big O Notation</li><li>Describe what a logarithm is</li></ul><p><strong>Imagine we have multiple implementations of the same problem.How can we determine which one is the “best?”</strong></p><h3>why big ‘O’ ?</h3><ul><li>It’s important to have a precise vocabulary to talk about how our code performs</li><li>When your code slows down or crashes, identifying parts of the code that are inefficient can help us find pain points in our applications</li><li>Less important: it comes up in interviews!</li></ul><h4>Example</h4><p>A program which calculates the sum of all numbers from 1 up to some number <em>n</em>.</p><pre>function addUpTo(n) {<br>  let total = 0;<br>  for (let i = 1; i &lt;= n; i++) {<br>    total += i;<br>  }<br>  return total;<br>}</pre><pre>function addUpTo(n) {<br>  return n * (n + 1) / 2;<br>}</pre><p>Which one you think is better?</p><h3>What does better mean?</h3><ul><li>Faster?</li><li>Less memory-intensive?</li><li>More readable?</li></ul><p>Let’s use timers to calculate speed</p><pre>function addUpTo(n) {<br>  let total = 0;<br>  for (let i = 1; i &lt;= n; i++) {<br>    total += i;<br>  }<br>  return total;<br>}</pre><pre>let initialTime = performance.now();<br>addUpTo(1000000000);<br>let finalTime = performance.now();<br>console.log(`Time Elapsed: ${(finalTime - initialTime) / 1000} seconds`)</pre><p>Time Elapsed: 2.653105000001262 seconds</p><pre>function addUpTo(n) {<br>  return n * (n + 1) / 2;<br>}</pre><p>Time Elapsed: 0.00004999999876599759 seconds</p><h3>The Problem with Time</h3><ul><li>Different machines will record different times</li><li>The <em>same</em> machine will record different times!</li><li>For fast algorithms, speed measurements may not be precise enough?</li></ul><h4>Counting operations is also hard!</h4><h3>Time Complexity</h3><blockquote>Big O Notation is a way to formalize fuzzy counting. It allows us to talk formally about how the runtime of an algorithm grows as the inputs grow</blockquote><p>We say that an algorithm is <strong>O(f(n))</strong></p><ul><li>f(n) could be linear (f(n) = n)</li><li>f(n) could be quadratic (f(n) = n² )</li><li>f(n) could be constant (f(n) = 1)</li><li>f(n) could be something entirely different!</li></ul><h4>Example</h4><pre>function addUpTo(n) {<br>  return n * (n + 1) / 2;<br>}</pre><h4>Always 3 operation,regardless of &#39;n&#39; so it is O(1)</h4><pre>function addUpTo(n) {<br>  let total = 0;<br>  for (let i = 1; i &lt;= n; i++) {<br>    total += i;<br>  }<br>  return total;<br>}</pre><h4>Number of operations is bounded by a multiple of ‘<em>n’ </em>(say, 100<em>n</em>) so it is O(n)</h4><pre>function countUpAndDown(n) {<br>  console.log(&quot;Going up!&quot;);<br>  for (let i = 0; i &lt; n; i++) {<br>    console.log(i);<br>  }<br>  console.log(&quot;At the top!\n Going down...&quot;);</pre><pre>  for (let j = n - 1; j &gt;= 0; j--) {<br>    console.log(j);<br>  }<br>  console.log(&quot;Back to bottom.&quot;);<br>}</pre><p>There are 2 for loops which are bounded by a multiple of n.</p><p>its is also O(n)</p><h4>one more example</h4><pre>function printAllPairs(n) {<br>  for (var i = 0; i &lt; n; i++) {<br>    for (var j = 0; j &lt; n; j++) {<br>      console.log(i, j);<br>    }<br>  }<br>}</pre><p>Nested for loops.<strong>O(n) operation inside of an O(n) operation.</strong></p><p>n * n = n² = O(n²)</p><h3>Smaller Terms Don’t Matter</h3><ul><li>O(2<em>n</em>) = <strong>O(<em>n</em>)</strong></li><li>O(500) = <strong>O(1)</strong></li><li>O(13<em>n </em>) = <strong>O(<em>n </em>)</strong></li><li>O(<em>n + </em>10) = <strong>O(<em>n</em>)</strong></li><li>O(1000<em>n</em> + 50) = <strong>O(<em>n</em>)</strong></li><li>O(<em>n </em>+ 5<em>n</em> + 8<em> </em>) = <strong>O(<em>n</em>)</strong></li></ul><h3>Big O Short hands</h3><ol><li>Arithmetic operations are constant</li><li>Variable assignment is constant</li><li>Accessing elements in an array (by index) or object (by key) is constant</li><li>In a loop, the the complexity is the length of the loop times the complexity of whatever happens inside of the loop</li></ol><h4>More examples</h4><h4>O(n)</h4><pre><br>function logAtLeast5(n) {<br>  for (var i = 1; i &lt;= Math.max(5, n); i++) {<br>    console.log(i);<br>  }<br>}</pre><h4>O(1)</h4><pre>function logAtMost5(n) {<br>  for (var i = 1; i &lt;= Math.min(5, n); i++) {<br>    console.log(i);<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*-pDZGkQqHuY5rZg5DBybZg.png" /><figcaption>Big O chart</figcaption></figure><h3>Logarithmic Complexity</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*UXmo1UrWqpRy0_IukRvNvw.png" /><figcaption>logarithm</figcaption></figure><p>We only deal with log with base 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/120/1*23dWQalnnTqWZAE0ImplhQ.png" /></figure><p>The logarithm of a number roughly measures the number of times you can divide that number by 2 <strong>before you get a value that’s less than or equal to one</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/175/1*qY8xwbmds-2lZ7gbMk8mTg.png" /><figcaption>log(8)</figcaption></figure><ul><li>Certain searching algorithms have logarithmic time complexity.</li><li>Efficient sorting algorithms involve logarithms.</li><li>Recursion sometimes involves logarithmic space complexity.</li></ul><h3>Space Complexity</h3><p>We can also use big O notation to analyze <strong>space</strong> <strong>complexity.</strong></p><h4>Rules of Thumb</h4><ul><li>Most <strong>primitives</strong> (booleans, numbers, undefined, null) are constant space</li><li>Strings require O(<em>n</em>) space (where <em>n</em> is the string length)</li><li>Reference types are generally O( <em>n</em>), where n is the length (for arrays) or the number of keys (for objects)</li></ul><pre>function sumOfAnArray(arr) {<br>  let total = 0;<br>  for (let i = 0; i &lt; arr.length; i++) {<br>    total += arr[i];<br>  }<br>  return total;<br>}</pre><p>We are just using primitives to compute. so it is <strong>O(1)</strong></p><pre>function doubleTheArray(arr) {<br>  let newArr = [];<br>  for (let i = 0; i &lt; arr.length; i++) {<br>    newArr.push(2 * arr[i]);<br>  }<br>  return newArr;<br>}</pre><p>We are using an extra array of size n. so it is <strong>O(n)</strong></p><h4>Find the Time Complexity</h4><pre>for(let i=0; i &lt; n; i++){ <br>      counter++;<br>}</pre><pre>for(let i=n; i &gt;= 0; i++){<br>   counter++;<br>}</pre><pre>for(let i=0; i &lt; n; i++){<br>    for(let j=0; j &lt; n; j++){<br>         counter++;<br>    }<br>}</pre><pre>for(let i=0; i &lt; n; i++){<br>    for(let j=0 ; j &lt; i; j++){<br>         counter++;<br>    }<br>}</pre><pre>let x = 0;<br>for(let i=1; x &lt;= n; i++){<br>         x = x+i;<br>         counter++;<br>}</pre><pre>function binarySearch(arr, key){<br>  let l = 0;<br>  let r = arr.length;<br>  if(arr.length === 1){<br>        return arr[0] === key;<br>  } <br>  while(l &lt; r){<br>        counter++;<br>        mid = Math.floor((l + r)/2);  <br>        console.log(arr[mid]);<br>        if(arr[mid] === key){<br>            return true; <br>        } <br>   <br>        else if(arr[mid] &lt; key){<br>            l = mid + 1;<br>        } <br>        else{<br>            r = mid - 1;<br>        }<br>      }</pre><pre>return false;<br>}</pre><pre>let arr = [];<br>for(let i=1;i&lt;=n;i++){<br>    arr.push(i);<br>}<br>binarySearch(arr,101);</pre><h4>Find the Space Complexity</h4><pre>for(let i=0; i &lt; n; i++){<br>    for(let j=0; j &lt; n; j++){<br>         arr[i][j] = 0;<br>    }<br>}</pre><pre>for(let i=0; i &lt; n; i++){<br>    arr.push(i);<br>}</pre><blockquote>Time complexity → CPU usage<br> Space complexity → RAM usage</blockquote><p>Happy coding 🎉 and Have a nice day🎊</p><p>To be Continued…</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f46d7deb81c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Structures and Algorithms(DSA) using JavaScript — Queue using Arrays]]></title>
            <link>https://medium.com/@yelloveprogrammer/data-structures-and-algorithms-dsa-using-javascript-queue-using-arrays-84f5fb983753?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/84f5fb983753</guid>
            <category><![CDATA[queue-using-array]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[harishsa]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 07:22:01 GMT</pubDate>
            <atom:updated>2020-06-03T07:22:01.468Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Structures and Algorithms(DSA) using JavaScript — Queue using Arrays</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oM-yjgBAizdDSOpW" /><figcaption>Photo by <a href="https://unsplash.com/@melanie_sophie?utm_source=medium&amp;utm_medium=referral">Melanie Pongratz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A Queue is a linear structure which follows a particular order in which the operations are performed</p><p>The order is<strong> First In First Out</strong> (FIFO)</p><h3>prerequisite</h3><ul><li>JavaScript Classes</li><li>Arrays</li></ul><h3>Applications</h3><ul><li>Servers</li><li>CPU scheduling</li><li>Call Center phone systems will use Queues</li><li>Breadth First search in a Graph</li></ul><h3>Operations</h3><p><strong>Enqueue: </strong>Adds an item to the queue. If the queue is full, then it is said to be an Overflow condition.<br><strong>Dequeue:</strong> Removes an item from the queue. The items are popped in the same order in which they are pushed. If the queue is empty, then it is said to be an Underflow condition.<br><strong>Front: </strong>Get the front item from queue.<br><strong>Rear:</strong> Get the last item from queue.</p><h3>Implementation</h3><h3>Using Builtin Methods</h3><pre>let queue = [];//Enqueue<br>queue.push(item);//Dequeue<br>queue.shift();</pre><h3>Our own Implementation</h3><pre>class Queue {  <br>       <br>         constructor(){<br>             this.queue = [];<br>             this.length= 0;<br>         }<br>          <br>         enqueue(val) {<br>              this.queue[this.length] = val;<br>              return this.length++;<br>         }    <br>    <br>         dequeue() {<br>              <strong>if</strong> (this.length === 0) {<br>                  console.error(&quot;Queue is empty&quot;);<br>                  <strong>return</strong>;<br>              } <strong>else</strong> {<br>                  let val = this.queue[0];<br>                  <strong>for</strong> (<strong>let </strong>i = 0; i &lt; this.length - 1; i++) { <br>                       this.queue[i] = this.queue[i + 1];<br>                   }<br>                  this.length--;<br>                  return val;<br>               } <br>        }<br>      <br>        peek(){<br>             return this.queue[0]; <br>        }</pre><pre>        rear(){<br>             return this.queue[this.length - 1];<br>        }</pre><pre>}</pre><p>Happy coding 🎉 and Have a nice day🎊</p><p>To be Continued…</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84f5fb983753" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Structures and Algorithms(DSA) using JavaScript — Queue using Linked List]]></title>
            <link>https://medium.com/@yelloveprogrammer/data-structures-and-algorithms-using-javascript-queue-8aabee76c207?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aabee76c207</guid>
            <category><![CDATA[queues-using-linked-list]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[harishsa]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 06:52:14 GMT</pubDate>
            <atom:updated>2020-06-03T08:29:53.302Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Structures and Algorithms(DSA) using JavaScript — Queue using Linked List</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L7PlZlntwabvStEL" /><figcaption>Photo by <a href="https://unsplash.com/@melanie_sophie?utm_source=medium&amp;utm_medium=referral">Melanie Pongratz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A Queue is a linear structure which follows a particular order in which the operations are performed</p><p>The order is<strong> First In First Out</strong> (FIFO)</p><h3>prerequisite</h3><ul><li>JavaScript Classes</li><li>Linked List</li></ul><h3>Applications</h3><ul><li>Servers</li><li>CPU scheduling</li><li>Call Center phone systems will use Queues</li><li>Breadth First search in a Graph</li></ul><h3>Operations</h3><p><strong>Enqueue: </strong>Adds an item to the queue. If the queue is full, then it is said to be an Overflow condition.<br><strong>Dequeue:</strong> Removes an item from the queue. The items are popped in the same order in which they are pushed. If the queue is empty, then it is said to be an Underflow condition.<br><strong>peek: </strong>Get the front item from queue.<br><strong>Rear:</strong> Get the last item from queue.</p><h3>Implementation</h3><pre>class Node{<br>      constructor(value) {<br>      this.value = value;<br>      this.next = null;<br>      }<br>}</pre><pre>class Queue {</pre><pre>         constructor(){<br>             this.first = null;<br>             this.last = null;<br>             this.length= 0;<br>         }<br>          <br>         enqueue(val) {<br>              let newNode = new Node(val);<br>              if (!this.first){ <br>                    this.first = newNode;<br>                    this.last = newNode;<br>              } else {<br>                    this.last.next = newNode;<br>                    this.last = newNode;<br>              }<br>              return ++this.length;<br>         }</pre><pre>        dequeue() {<br>              if (!this.first) return null;<br>              var temp = this.first; <br>              if (this.first === this.last) {<br>                    this.last = null;<br>              }<br>              this.first = this.first.next;<br>              this.length--;<br>              return temp.value;<br>         }</pre><pre>       peek(){<br>             return this.first; <br>       }</pre><pre>       rear(){<br>             return this.last;<br>       }</pre><pre>}</pre><p>Happy coding 🎉 and Have a nice day🎊</p><p>To be Continued…</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aabee76c207" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Beginner’s Guide to Programming using JavaScript — Strings[part-8]]]></title>
            <link>https://medium.com/@yelloveprogrammer/the-ultimate-beginners-guide-to-programming-using-javascript-strings-part-8-6a652278804d?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a652278804d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[strings-in-js]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Fri, 22 May 2020 07:56:03 GMT</pubDate>
            <atom:updated>2020-05-22T07:56:03.002Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Beginner’s Guide to Programming using JavaScript — Strings[part-8]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D5lhccrIECUn0zo0" /><figcaption>Photo by <a href="https://unsplash.com/@anniespratt?utm_source=medium&amp;utm_medium=referral">Annie Spratt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>what are strings?</h3><p>JavaScript strings are used for <strong>storing and manipulating text</strong>.A JavaScript string is zero or more characters written inside quotes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*tfL8EfsFyif6DYg2s5ISEg.png" /><figcaption>Strings</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pJYfNiDdpRJq-ShmXxfhMw.png" /><figcaption>console.log of string</figcaption></figure><h3>Creating Strings</h3><p>we can create string by using</p><ul><li><strong>Double quotes</strong><strong>(&quot;)</strong></li><li><strong>Single quotes</strong><strong>(&#39;)</strong></li><li><strong>new operator</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*D8cgiNW6rhi2KTFBR3vEOQ.png" /><figcaption>Using Double Quotes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*Bqv7n3bDcMMaMlmYKqS0tA.png" /><figcaption>Using single quotes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*UrAEuYceMaELI8cpurjldQ.png" /><figcaption>using new Operator</figcaption></figure><p>Don’t create strings as objects. It slows down execution speed.<br>The new keyword complicates the code.</p><h3>Accessing the data</h3><p>We can access the data inside a string using</p><ul><li><strong>[]</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*AjE3lAa9QWBVim42p2ZImA.png" /><figcaption>Accessing characters using <strong>[ ]</strong></figcaption></figure><p>String is a collection(Array) of characters.we can access a string like we access an array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*prLUXb7FUuMEixQ_yYl24g.png" /><figcaption>Accessing string</figcaption></figure><p>when we try to access the index which is out of bound , then it will print undefined .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UvP_LBk3KWFF8fz_uuMfMw.png" /><figcaption>Accessing out of bound characters</figcaption></figure><h3>String Methods</h3><p>Some of the most-used operations on strings are to check their length, to build and concatenate them using the + and += string operators, checking for the existence or location of substrings with the indexOf() method, or extracting substrings with the substring() method.</p><h4>length</h4><p>The <strong>length</strong> property of a String object contains the length of the string</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*xeBcjYg2Ku13ihE1rCiA_g.png" /><figcaption>String length property</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bT4XMKCFf5ifPK4FWvGlww.png" /><figcaption>String length</figcaption></figure><h4>concatenating two or more strings</h4><p><strong>using </strong><strong>+</strong></p><p>we can concatenate two or more strings using + .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*blLq8R1zsl2BTMloJz7etg.png" /><figcaption>Concatenating two strings</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fEDhHGZeE_wAUKvL4cI4A.png" /></figure><p>We can also add space between two strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*PV4v_TebTau5I6XZ5Z6WMw.png" /><figcaption>Concatenating three strings</figcaption></figure><p>Space is also a strings.it has it’s own ASCII value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CkwrPy3QCUDomUbQ2xe4Ig.png" /></figure><h4>Using String.concat()</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*5H2nAeCyERAilu8gXhOqzA.png" /><figcaption>Using string.concat</figcaption></figure><p><strong>syntax is</strong></p><pre>&lt;string 1&gt;.concat(&lt;string 2&gt;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7NBAmjdvPyVBbM0PGX05g.png" /></figure><p><strong>concat</strong>enating with space</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6pVCT3F5Z3jasSnW9OpUeQ.png" /><figcaption>Concatenating three strings using concat</figcaption></figure><h4>substring</h4><p>we can use sub string to slice particular string from the string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*qpx4iZKX-QCoJ-84S1pKZA.png" /><figcaption>Substring</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRnqDkb8LcM2PM7PuJUFHA.png" /></figure><p>There are lots of string methods like this available.You can read about them all in mdn docs.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String - JavaScript | MDN</a></p><p>Happy coding 🎉 and Have a nice day🎊</p><p>Up next Math in JavaScript 🤩</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a652278804d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Beginner’s Guide to Programming using JavaScript — Objects [part-7]]]></title>
            <link>https://medium.com/@yelloveprogrammer/the-ultimate-beginners-guide-to-programming-using-javascript-objects-part-7-f95c674e7555?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/f95c674e7555</guid>
            <category><![CDATA[javascript-object]]></category>
            <category><![CDATA[harish-sambasivam]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Tue, 19 May 2020 15:01:04 GMT</pubDate>
            <atom:updated>2020-05-19T15:08:05.935Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Beginner’s Guide to Programming using JavaScript — Objects [part-7]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h8e0g8TSKAHN_zf2" /><figcaption>Photo by <a href="https://unsplash.com/@bialons?utm_source=medium&amp;utm_medium=referral">the Bialons</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Objects are the foundation of JavaScript and permeate its every aspect. <strong><em>Almost </em></strong>everything in JavaScript is an object. In fact, only <strong>six</strong> things are <strong>not</strong> objects. They are — <strong><em>null</em></strong>,<strong><em>undefined</em></strong>, <strong><em>strings</em></strong>, <strong><em>numbers</em></strong>, <strong><em>boolean</em></strong>, and <strong><em>symbols</em></strong>. These are called primitive values or primitive types.</p><p>Anything that is not a primitive value is an <strong>Object</strong>. That includes <strong>arrays</strong>, <strong>functions</strong>, constructors, and objects themselves. Yes! Functions and arrays are objects too as we shall see later in the article.</p><h3>What are objects?</h3><p>objects are values too and they serve the same purpose: <strong>Representing information or data</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*UPyVcEECT47EUj0SK2TSiQ.png" /><figcaption>Object</figcaption></figure><p>Object is just a collection of key:value (properties) pairs.</p><p>cat is an object which holds all the data like name,color,food etc…</p><pre>console.table(cat)</pre><p>Like we used console.table for array ,we can use that for objects also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SF623I7ojchOfhHxIMTetQ.png" /><figcaption>Object of a cat</figcaption></figure><h3>Creating Objects</h3><p>we can create object by using</p><ul><li>Object literals {}</li><li>new operator</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*mgAXykluPEZlIygnYuXuCA.png" /><figcaption>Object literals</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SF623I7ojchOfhHxIMTetQ.png" /><figcaption>Object of a cat</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*dtPZyFWljDXRgS1rpZo2VQ.png" /><figcaption>using new operator</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_x96KBYE4Xo-v6_PpB02GA.png" /><figcaption>Object of a cat</figcaption></figure><p>You can notice, object literal is the easiest and elegant way to create objects.</p><h3>Accessing the data</h3><p>We can access the data inside an object using</p><ul><li><strong>using (.)</strong></li><li><strong>using []</strong></li></ul><h3>Dot Notation</h3><p>To access data inside an object we can use .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*VgBvunY3LN-8WTH_OnUpXQ.png" /><figcaption>Accessing data using Dot Notation</figcaption></figure><p>In our example, cat is an object.To print the name of the cat which is stored inside the object we can use cat.name</p><p>syntax is</p><pre>objectName.propertyName</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gUMw0JWvvJypCFRSm2ADTw.png" /><figcaption>Dot Notation</figcaption></figure><h3>using Bracket Notation</h3><p>It’s like accessing data inside an array.But instead of specifying index number we need to specify the key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SF623I7ojchOfhHxIMTetQ.png" /><figcaption>Object of a cat</figcaption></figure><p>You can notice index column have all the keys.In objects keys are the indices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8yxXI_IAqSvMX1ZcWAtF-w.png" /><figcaption>Accessing data with Bracket Notation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XyrOkbp7lTfaPiMmqxQk7g.png" /></figure><h3>Objects with Functions</h3><p>We can also have functions as an object property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*IPdO7hWsVOgF82GAIHhEEA.png" /><figcaption>Functions as property</figcaption></figure><p>To instantiate the function, we need to access the property using any of two methods we learned and then instantiate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*F1KBH4rLTGVqjmxTTtaSUQ.png" /><figcaption>Instantiating a function inside object</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CzV6dYUw7c7VQgQFzTlMpQ.png" /></figure><p>we can have arrays,functions,objects and all the other datatypes we discussed inside a object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dnmmsWjDWNDv7_glamQdNA.png" /><figcaption>Nested Objects</figcaption></figure><p>You can notice we have a property called “enemies”.which is an object itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*HbTTUvd6-4pBoVKwvS9MGw.png" /><figcaption>Accessing enemies</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Mgq9RXHmJn_pxgq_618Mg.png" /><figcaption>Accessing enemies</figcaption></figure><p>We can use console.table instead of console.log to prettify it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0pqwN85MMjj9YFlpVww7Gw.png" /><figcaption>Nested dot notations</figcaption></figure><p>You can see it’s getting deeper. we have object called cat which in turn have an object called enemies which holds another object called rat and dog</p><p>We can avoid nested dot notation by introducing an intermediate variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xhR0x-4wnHHyxhIS9i3giQ.png" /></figure><p>Storing cat.enemies into enemies and then accessing rat by dot notation on the intermediate variable.</p><p>Intermediate variable, need not to be named same as property name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CLXAJR-ZDBvALvPu35EiDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RyWKVZQxlk359Cuk3gC4cA.png" /></figure><h3>Object.keys</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*JcezOU3U1YucaWAbE4t_8Q.png" /><figcaption>Object.keys()</figcaption></figure><p>syntax is</p><pre>Object.keys(&lt;object&gt;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uAIb6Tvpi_0PHtQCxOBSVg.png" /><figcaption>Object.keys</figcaption></figure><p>You can see in console an array with all the keys are printed.Object.keys returns an array of all the keys.</p><h3>Object.values</h3><p>It’s similar to how Object.keys() work.instead of keys it returns an array of values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*MQ7BotrsnPYblTLDg4Wc0Q.png" /><figcaption>Object.values</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YJtNHqFWAGZKAbp8GbJYVA.png" /></figure><p>we are done with the fundamentals of objects🤪.You can read the advanced topics on objects from mdn docs.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object - JavaScript | MDN</a></p><p>Happy coding 🎉 and Have a nice day🎊</p><p>Up next JavaScript Strings 🤩</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f95c674e7555" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Beginner’s Guide to Programming using JavaScript — Functions [part-6]]]></title>
            <link>https://medium.com/@yelloveprogrammer/the-ultimate-beginners-guide-to-programming-using-javascript-functions-part-5-5a72972e836b?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a72972e836b</guid>
            <category><![CDATA[harish-sambasivam]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functions-in-javascript]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Tue, 19 May 2020 09:47:21 GMT</pubDate>
            <atom:updated>2020-05-19T15:10:07.004Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Beginner’s Guide to Programming using JavaScript — Functions [part-6]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f7JKQQX9-c772n9P" /><figcaption>Photo by <a href="https://unsplash.com/@jakeacharles?utm_source=medium&amp;utm_medium=referral">Jake Charles</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>before we discuss what is a function.Let’s make lemon juice.</p><p>How do you make a lemon juice?</p><ol><li>pour water in a glass.</li><li>Add sugar to it.</li><li>squeeze the lemon.</li><li>stir it well.</li></ol><p>Now your 🍋 juice is ready.</p><p>Now when you want me to make a lemonade for you, what do you say?</p><p>same steps above right ?.</p><p>In JavaScript or any other programming language, a function is like a recipe of certain tasks.</p><p>This makes the life of a programmer much more easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Q9PEHDp2DjdvvVuiRZD2Q.png" /><figcaption>Function</figcaption></figure><p>The above is a simple function</p><p>syntax is</p><pre>function &lt;name of the function&gt; {</pre><pre>              //   body of the function </pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VU24i3Y9Y7uPZeraIFzLyw.png" /></figure><p>You can notice nothing showed up in console.Don’t worry that’s expected.what we did just is “we declared a function”.</p><p>We need to instantiate the function.we can do that by</p><pre>&lt;name of the function&gt;()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*wj2Akb9AWjcO-1oGqNFyuQ.png" /><figcaption>Instantiating a function</figcaption></figure><p>let’s instantiate and see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RWp0Vkvn0rhM8u0Ex-KydQ.png" /></figure><p>You can notice something printed on the console.</p><p>watersugar🍋 because + operator concatenates all the string.we will discuss about string concatenation in a medium post dedicated to strings.</p><h3>different ways to define functions</h3><h3>1. Function Declaration/Statement</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Q9PEHDp2DjdvvVuiRZD2Q.png" /><figcaption>Function Declaration/Statement</figcaption></figure><h3>2. Function Expression</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VVV1W5CzYHGtk1YG_4zM3Q.png" /><figcaption>Function Expression</figcaption></figure><p>In JavaScript, We can store functions in a variable by using function expression syntax.</p><h4>Anonymous Function</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l9dprpVzhg_XX0z_hyzjXA.png" /><figcaption>Anonymous Function</figcaption></figure><p>Function without a function name is called <strong>Anonymous Function</strong></p><p>we store anonymous function in a variable and we instantiate that variable to run the function.</p><h3>Arrow Function</h3><p>Array function is another way to define function in JavaScript.We replace keyword function with =&gt; .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EdxY0xp4AcNLB0IeUEuhTw.png" /><figcaption>Arrow Function</figcaption></figure><p>Normal functions and arrow functions have some differences which are advanced topics.</p><p>we will discuss them in separate medium post on <strong>this </strong>keyword.</p><p>We are kind of distracted away,let go back to makeLemonJuice function.Main reason we go for functions is code reuse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IX6bpcYlXfVotB5xCUYM6g.png" /><figcaption>Code reuse</figcaption></figure><p>we can use same function to make as many juices as we can by instanciating it again and again.</p><h3>Lets make more juices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ftSHm0gds69Bsa17PnxyPQ.png" /></figure><p>I made more functions with different names to make different juices.can we reduce the number of lines of code we wrote?</p><p>yup, we can.</p><h3>Function with parameters</h3><p>let’s discuss this topic by creating function for making juice(not just lemon juice).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2LQCGICWGfOkqyjkGjEkcA.png" /><figcaption>Function with parameters</figcaption></figure><p>You can notice function takes some value inside () ,fruit in our case.Now we can pass any fruit which we want to squeeze and add to juice.</p><p>let’s see our juicer function in action😍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GJ9kmvagE1a5chHsSRBAJQ.png" /></figure><p>You can see , when instantiating function i passed something in between () which is a carrot🥕 ,since function definition is accepting a parameter called fruit .Now carrot becomes fruit(i know 🥕 is a vegetable😂).it matches the signature.</p><p>Now our function replaces the fruit in the function body with the passed parameter.</p><p>let’s make some more juices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WVibxifbE0MEbuRyXqHSew.png" /></figure><p>You can notice we made</p><ul><li>carrot juice</li><li>mango juice</li><li>lemon juice</li><li>apple juice</li><li>banana juice</li><li>orange juice</li><li>pine apple juice</li></ul><p>hmm.. we can start a juice shop with them.</p><h3>let’s compare</h3><p>You can compare how much line we wrote to make 4 juices and single function with parameters to make 7 juices.</p><p>function are the way to reuse the code we wrote.</p><p>I hope , You understood basics of functions,let’s write a program to make sense.</p><p>A function which accepts two parameters(yup. we can pass as many parameters as we can to a function) and calculates the sum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JX5zMnJ6NaapDvjC9bKsgg.png" /></figure><p>it’s our function to print sum of passed two numbers to the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1lEpmGLUndqOOv_De7JO6g.png" /></figure><blockquote>+ is a operator to add two numbers</blockquote><p>one thing before i end this post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*aPAbxZ7_StQNyydDHVdIlQ.png" /></figure><p>Never ever write functions like this.Follow the simple guidelines i mentioned for variables,even when naming functions and function parameters.</p><p><a href="https://medium.com/@yelloveprogrammer/the-ultimate-beginners-guide-to-programming-using-javascript-variable-naming-conventions-part-4-fbf4d53770c4">The Ultimate Beginner’s Guide to Programming using JavaScript — Variable Naming Conventions[part-4]</a></p><p>Happy coding 🎉 and Have a nice day🎊</p><p>Up next JavaScript Objects 🤩</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a72972e836b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Beginner’s Guide to Programming using JavaScript — Arrays[part-5]]]></title>
            <link>https://medium.com/@yelloveprogrammer/the-ultimate-beginners-guide-to-programming-using-javascript-arrays-part-4-9d700758b31?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d700758b31</guid>
            <category><![CDATA[harish-sambasivam]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-arrays]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Tue, 19 May 2020 08:16:14 GMT</pubDate>
            <atom:updated>2020-05-19T10:50:02.813Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Beginner’s Guide to Programming using JavaScript — Arrays[part-5]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QIrpeYb92BiLQm8O" /><figcaption>Photo by <a href="https://unsplash.com/@filipbaotic?utm_source=medium&amp;utm_medium=referral">Filip Baotić</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Like we store vegetables in a basket,let’s store vegetables in a array🤗️</p><h3>Declaration of an Array</h3><p>There are basically two ways to declare an array.</p><h4><strong>With the literal notation []</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P-EAvM-eXmPZX8D28KBu_g.png" /><figcaption>vegetable basket</figcaption></figure><h4><strong>With the Array() constructor</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eGyizVcU_TY4be7K2wwsqg.png" /><figcaption>vegetable basket</figcaption></figure><p>Both the approaches are same.Most people prefer the first approach(literal notation) because it uses less code.</p><h3><strong>Accessing values of arrays</strong></h3><p>We can access the values of an array by referring to an index number.</p><ul><li>Array index starts from 0.</li><li>To get the value we refer to the members of an array using the index number in a square bracket []</li></ul><p>if i want to access ‘🧅’ how can i do that?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MtJhWbpGYFjawSfASTDfXQ.png" /><figcaption>Accessing elements inside Array</figcaption></figure><ul><li>All the vegetables inside array are called Array Elements</li><li>Every element in an array corresponds to particular index number</li><li>Garlic🧄 corresponds to index number 0</li><li>Mushroom🍄 corresponds to index number 8</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zITndNCUHqPUoYpcI5hjog.png" /><figcaption>Accessing array elements</figcaption></figure><h3>console.table()</h3><p>we can use console.table to print array into console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ux-Wf1VgbFR_etHNQ8zYtQ.png" /><figcaption>console.table</figcaption></figure><h3>Adding or Removing elements from an Array</h3><p>JavaScript provides various methods to add, remove or change data of an array.</p><h4>Array.push</h4><p>we can add elements to end of the array with Array.push</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EDOi0kWvpZHrUIoYzO_9og.png" /><figcaption>push</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3xa9EKVK1C3STtU8zdT4sw.png" /></figure><p>You can notice cucumber🥒 at end of the array.</p><h4>Array.pop</h4><p>we can remove an element from end of an array with Array.pop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ULWDFMk8Mpw4_JWV6nqi5Q.png" /><figcaption>Array.pop</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*asfrDkwf-agTfcrvafosEA.png" /></figure><p>You can notice mushroom is removed from our vegetable Basket.</p><p>when pushing we need to specify the element to push into array like push(‘🍄’).But when removing we need not to specify anything to pop() function.</p><p>these magic things pop,push are called methods.since we are performing operations on arrays its called Array methods .</p><p>They are already written by the developers who built JavaScript. we can make use of them.</p><p>we will make our own functions/methods in upcoming posts.</p><h4>Let’s also discuss one important thing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q-Dx25ECqSAdmKS_b2txgA.png" /></figure><p>Look at this Screenshot, when i console logged the push and pop operations, it logged something in the console.</p><pre>console.log(vegetableBasket.push(‘🥒’));</pre><p>This line prints 9 because cucumber🥒 is pushed at the array index 9.</p><p>It’s called <strong>returning a value.</strong></p><p>For now,just know that these built in JavaScript functions give us something back when we run them.like in our case it returns ‘9’ which is index of the inserted element.</p><p>we will discuss thoroughly about return when we discuss functions in JavaScript.</p><p>similarly,</p><pre>console.log(vegetableBasket.pop());</pre><p>pop function returns the popped element which is 🥒.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KmFTGzvhoSlmAV3tUZMdMQ.png" /></figure><h4>Array.unshift</h4><p>Inserting element to front of the array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_jijgW7q23pHilDoFIpEtA.png" /><figcaption>Array.unshift</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cGcky9DnmYBrFDF2uRuzmg.png" /></figure><p>You can notice,unshift inserted the coconut🥥 to front of the array.</p><p>what about removing from front?</p><h4>Array.shift()</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yt1K3nwHTvyDqwpDZRn75g.png" /><figcaption>Array.shift</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S9y-op8YyeeAOQ6fupozeg.png" /></figure><p>You can notice, Garlic is removed from front of the array.</p><pre>push ~ unshift          returns index of inserted element.</pre><pre>pop ~ shift             return removed element. </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GXNtOiGXtbkuMOxMy_yaA.png" /></figure><h4>Array.length</h4><p>we can find the length of array using Array.length</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hQAvcZvWWFqVMkvpfpsZqw.png" /></figure><p>it counts number of elements in the array and returns it.</p><p>There are lots of builtin methods like these out there. we will cover them all as we go along.You can check them out in mozilla developer network(MDN) docs, if you are very much interested in learning them.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Instance_methods">Array</a></p><p>Happy coding 🎉 and Have a nice day🎊</p><p>Up next JavaScript Functions🤩</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d700758b31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Beginner’s Guide to Programming using JavaScript — Variable Naming Conventions[part-4]]]></title>
            <link>https://medium.com/@yelloveprogrammer/the-ultimate-beginners-guide-to-programming-using-javascript-variable-naming-conventions-part-4-fbf4d53770c4?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbf4d53770c4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[naming-conventions]]></category>
            <category><![CDATA[casing]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Tue, 19 May 2020 05:29:33 GMT</pubDate>
            <atom:updated>2020-05-19T05:36:47.584Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Beginner’s Guide to Programming using JavaScript — Variable Naming Conventions[part-4]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eN0g65_dL0yrLg_4" /><figcaption>Photo by <a href="https://unsplash.com/@jontyson?utm_source=medium&amp;utm_medium=referral">Jon Tyson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>There are only two hard things in Computer Science: cache invalidation and naming things.</em></blockquote><blockquote><em>— Phil Karlton</em></blockquote><p>Before we dig deeper into naming conventions,let’s discuss about some ways we can combine our variable names together which is easier to read.</p><h3>Case Styles</h3><blockquote>The most popular ways to combine words into a single string</blockquote><ul><li>camel Case</li><li>Pascal Case</li><li>snake_case</li><li>kebab-case</li></ul><h3>Camel Case</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1K0HYyRWb-v6N9pH" /><figcaption>Photo by <a href="https://unsplash.com/@sickle?utm_source=medium&amp;utm_medium=referral">Sergey Pesterev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://en.wikipedia.org/wiki/Camel_case">Camel case - Wikipedia</a></p><p>we capitalise the word’s first letter except the first word.</p><p><strong><em>Raw:</em></strong> number of likes</p><p><strong><em>Camel case:</em></strong><em> </em>numberOfLikes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*s1EwHJRfAS4bia4GIHy-IQ.png" /><figcaption>Camel Case</figcaption></figure><h3>Pascal Case</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ADDnihH6eTTiOGB6" /><figcaption>Photo by <a href="https://unsplash.com/@d_dmd2?utm_source=medium&amp;utm_medium=referral">Dario Didon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We just capitalize first letter of every word.</p><p><strong><em>Raw:</em></strong> number of likes</p><p><strong><em>Pascal case:</em></strong><em> </em>NumberOfLikes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*vs7-rDdt1VuRbUSpv9avsA.png" /><figcaption>Pascal Case</figcaption></figure><h3>Snake Case</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*woOSw72r7TtFM1lu" /><figcaption>Photo by <a href="https://unsplash.com/@acastrophotocr?utm_source=medium&amp;utm_medium=referral">Alfonso Castro</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Snake case combines words by replacing each space with an underscore (_) and, in the all caps version, all letters are capitalized, as follows:</p><p><strong><em>Raw:</em></strong> number of likes</p><p><strong><em>Snake Case:</em></strong><em> </em>number_of_likes</p><p><strong><em>Snake Case (All Caps):</em></strong> NUMBER_OF_LIKES</p><p>Capitalized name , is often used as a convention in declaring constants in many languages. When lower cased, it is used conventionally in declaring database field names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*9zBZq9MmxT4YUOEggBwhTg.png" /><figcaption>Snake case</figcaption></figure><h3>Which one is best?</h3><p>There is no best method.Be consistent with one casing convention or if you’re working as team then follow the team’s preferred casing convention.</p><p>Now we are ready to discuss good and bad naming conventions!!!</p><h3>why naming variables is so important?</h3><ul><li>Your code will be read more times than it is written.</li></ul><h3>What Causes Bad Variable Names?</h3><p>Most problems with naming variables stem from</p><ul><li>A desire to keep variable names short.</li><li>A direct translation of formulas into code.</li></ul><h3>Use Descriptive names</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CM5q6C3sQfnqoPpb0fFeRQ.png" /><figcaption>Poor naming conventions vs descriptive naming conventions</figcaption></figure><h3>Use Consistent Casing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Th8EygF99M8qv3A6SnynnQ.png" /><figcaption>Consistent Casing</figcaption></figure><p>since we are just starting out, Follow these conventions for now.We just touched the tip of iceberg🤪</p><p>We will discuss further conventions to make our code readable, as we move through our journey.</p><p>Happy coding 🎉 and Have a nice day🎊</p><p>Up next JavaScript Arrays🤩</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbf4d53770c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Beginner’s Guide to Programming using JavaScript — Data types [part-3]]]></title>
            <link>https://medium.com/@yelloveprogrammer/the-ultimate-beginners-guide-to-programming-using-javascript-data-types-part-3-be28a813fd75?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/be28a813fd75</guid>
            <category><![CDATA[harish-sambasivam]]></category>
            <category><![CDATA[datatypes-in-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[harish-sa]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Mon, 18 May 2020 10:55:30 GMT</pubDate>
            <atom:updated>2020-05-18T13:19:19.474Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Beginner’s Guide to Programming using JavaScript — Data types [part-3]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qyv8mpAcjFdG_8Ma" /><figcaption>Photo by <a href="https://unsplash.com/@charlesdeluvio?utm_source=medium&amp;utm_medium=referral">Charles Deluvio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>what is a Data type?</h3><p>Data types are used to classify one particular type of data from another in programming languages.</p><p>for instance,<strong>number</strong> and <strong>string</strong> are two different data types which are handled differently by JavaScript.</p><p>To distinguish Numbers from other data types ,we need to mention it is a Number datatype to JavaScript so we can perform <strong>Arithmetic Operations</strong> like addition,subtraction on the data.</p><h3>Dynamically Typed</h3><p>As we discussed in previous posts, JavaScript is dynamically typed which means we need not to mention data type to compiler.</p><h4>Then how JavaScript understands the datatype of defined variable🤔?</h4><p>Before we dig into that topic,lets see what are all the data types available in JavaScript✌</p><ul><li><strong>Numbers</strong></li><li><strong>BigInt</strong></li><li><strong>Strings</strong></li><li><strong>Boolean</strong></li><li><strong>Arrays</strong></li><li><strong>Objects</strong></li><li><strong>Undefined</strong></li><li><strong>Null</strong></li><li><strong>Symbols</strong></li></ul><h3>Primitive Data Types 🆚 Derived(Non primitive) Data Types</h3><p><strong>Buzz words</strong>😜</p><p><strong>Primitive datatype</strong> are type provided by the programming language as the basic building block like number,string,null,undefined,Boolean. <strong>Primitive datatype get the memory allocation at compile time</strong>.</p><blockquote><strong>Compile time</strong> means when the compilation is started by the compiler.i feel like its a bit confusing topic to explain it for beginners.read the stack overflow post and geeks for geeks blog for further details👇</blockquote><ul><li><a href="https://stackoverflow.com/questions/846103/runtime-vs-compile-time">Runtime vs. Compile time</a></li><li><a href="https://www.geeksforgeeks.org/difference-between-compile-time-errors-and-runtime-errors/">Difference between Compile Time Errors and Runtime Errors - GeeksforGeeks</a></li></ul><p><strong>Derived datatype</strong> are type which are derived from the existing primitive datatype bundled together like array,object etc. <strong>Derived datatype just get the reference to that memory allocation where value are saved</strong>.</p><h3>Number</h3><p>Number is used to store integer and floating point values in JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*I8pNk_KHoKLkK42mjhMf2g.png" /><figcaption>Adding two numbers by using two integer values of data type ‘Number’</figcaption></figure><h3>typeof operator</h3><p>To find data type of a variable, we can use typeof operator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SjtbwcemYY8-9eefky8Q4w.png" /><figcaption>You can check the type of <strong>one</strong> and <strong>cow</strong> in console.</figcaption></figure><p>JavaScript uses same data type to store decimal values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkXRxX-lslPXzcEVWx-l-A.png" /><figcaption>typeof integer and floating point value.</figcaption></figure><p>Scientific exponential notation can be used in JavaScript to abbreviate very large or small numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*YZEginWd1xBCVsPdvWfmRQ.png" /><figcaption>Using Scientific exponential notation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1AXzuLCJzbWdgAEt59QILg.png" /><figcaption>Using Scientific exponential notation</figcaption></figure><p>In addition to representing numbers, the JavaScript number type also has three symbolic values available:</p><ul><li>Infinity — a numeric value that represents a positive number that approaches infinity</li><li>-Infinity— a numeric value that represents a negative number that approaches infinity</li><li>NaN — a numeric value that represents a non-number, standing for not a number</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*E1na7N61dTSCE7ZVJGY66Q.png" /><figcaption>Infinity</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jIBgTaGNKYO-oG97hUtMTg.png" /><figcaption>NaN and Infinity</figcaption></figure><p>Number.MAX_SAFE_INTEGER is way to find the safest maximum integer in JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKtE2ceKF7ZGG_tnZoUafg.png" /><figcaption>MAX_SAFE_INTEGER</figcaption></figure><p>the numbers higher 9007199254740991 than will behave unexpected.To overcome that issue JavaScript introduced a new datatype called <strong>BigInt.</strong></p><p>We will discuss that unexpected behavior in upcoming blogs.You can read that from MDN web docs</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER">Number.MAX_SAFE_INTEGER</a></p><h3>BigInt</h3><p><strong>BigInt</strong> provides a way to represent whole numbers larger than 2^53 - 1, which is the largest number JavaScript can reliably represent with the Number primitive and represented by the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER">Number.MAX_SAFE_INTEGER</a> constant.</p><p>Creating a bigint data type is bit different compared to other data types.</p><ol><li>appending ’n’ to the end.</li><li>using BigInt() function.</li></ol><p>let’s see both of them in action</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dIYh2_0_fgIdGBWmHMBsEg.png" /><figcaption>Digging deeper with BigInt</figcaption></figure><p>I can understand your feelings. It’s a bit more lines of code😜</p><p>just run them line by line yourself.</p><p>Rule of thumb: Only use BigInt’s for huge calculations.</p><h3><strong>Strings</strong></h3><p>A string is a sequence of one or more characters (letters, numbers, symbols).we represent text using <em>String</em> data type in JavaScript.</p><p>In JavaScript,To represent String we need to wrap the text inside either in Single Quotes (‘) or Double Quotes(“).</p><pre>const singleQuotesExample = ‘This is a string example 👆’;</pre><pre>const doubleQuotesExample = “This is a string example ✌”;</pre><h3>Boolean</h3><p>The Boolean data type can be one of two values, either true or false.</p><p>simple isn’t it🤪.But very important datatype.</p><p>Many operations in math give us answers that evaluate to either true or false:</p><ul><li>greater than</li><li>500 &gt; 100 true</li><li>1 &gt; 5 false</li><li>less than</li><li>200 &lt; 400 true</li><li>4 &lt; 2 false</li><li>equal</li><li>5 == 5 true</li><li>500 == 400 false</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_b5UjD4miEqp-Q2RSj2tPQ.png" /><figcaption>Is mouse small in size than an elephant?</figcaption></figure><p>Conditional Statements and loops uses Boolean datatype to apply conditions.</p><h3>Arrays</h3><p>An array can hold multiple values within a single variable.</p><p>Just as strings are defined as characters between quotes, arrays are defined by having values between square brackets [ ].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RNq9m24vBrNtK67Txa6pEA.png" /><figcaption>List containing Vegetables</figcaption></figure><p>We can store any data types inside a single array unlike most programming languages out there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fEjPwK2OdnzQo0Ju3MjHCQ.png" /><figcaption>Mixture🥗</figcaption></figure><p>We can even store array inside an array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LALvE-QeOU_9iqFELD2cgw.png" /><figcaption>Nested Array</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BjSoYB4S6dSIktHO7H2miQ.png" /><figcaption>Array of fishes</figcaption></figure><h3>Objects</h3><p>Object = key:value pair</p><p>Just as Arrays are defined as values between square brackets , Objects are defined by having values between square brackets {}.</p><p>Inside curly brackets, we can have ’n’ number of Key:Value pairs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*ys_1LSqUVDtC1v8GFJtCWw.png" /><figcaption>JavaScript Object</figcaption></figure><p>We have an object called pet. Mostly we use objects to store <em>real world objects</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*154g-JbtBymXhna7OQWeIA.png" /><figcaption>Example of nested object</figcaption></figure><p>Here, address is an object which holds some key value pairs.</p><h3>Undefined</h3><p>Special type of data type in JavaScript.</p><p>1.Whenever we declare a variable without assigning any value to it, JavaScript implicitly assigns its value as undefined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*AVWuMWQ9Or0gl7uIX_8LOQ.png" /><figcaption>Undefined in JavaScript</figcaption></figure><p>2.When value is not assigned in array or object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CBV8mSEa8uEwxbLTrT9jPQ.png" /><figcaption>Undefined in Arrays</figcaption></figure><p>3) When functions don’t have a return statement but are called for assigning a value to a variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*Pd250k5wsVFoRfcLUWSlgQ.png" /><figcaption>Undefined and functions</figcaption></figure><h3>Null</h3><p>Null essentially represents a non-existent or an empty value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*FqTK1zI7i7FrkfOcZ0qMMA.png" /><figcaption>Null in JavaScript</figcaption></figure><p>We use null to initialize variable as non existing .Later we update that variable.</p><h3>Symbols</h3><p>The data type <strong>symbol</strong> is a <a href="https://developer.mozilla.org/en-US/docs/Glossary/Primitive">primitive data type</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*tLFIOcmO4pJkm458WhiFPw.png" /><figcaption>Symbol in JavaScript</figcaption></figure><p>Symbol() creates unique identifier which we can make use of. We will discuss symbols in separate Article.</p><p>Happy coding 🎉 and Have a nice day🎊</p><p>Up next Variable naming conventions and rules🤩</p><blockquote><em>Don’t forget to applause if you found it helpful😜</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be28a813fd75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Beginner’s Guide to Programming using JavaScript — Variables [part-2]]]></title>
            <link>https://medium.com/@yelloveprogrammer/the-ultimate-beginners-guide-to-programming-using-javascript-variables-part-2-189802256650?source=rss-7ad7abd87578------2</link>
            <guid isPermaLink="false">https://medium.com/p/189802256650</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[programming-for-beginners]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[variables-in-programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[The Coding Bear]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 14:00:38 GMT</pubDate>
            <atom:updated>2020-05-18T14:00:06.667Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Ultimate Beginner’s Guide to Programming using JavaScript — Variables [part-2]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DJac68-daaorUrIz" /><figcaption>Photo by <a href="https://unsplash.com/@jtylernix?utm_source=medium&amp;utm_medium=referral">Tyler Nix</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Before we start let’s understand why we need to know what is a variable.To perform computation, we need to store the data in our computer first. for example, To add two numbers we need to store these numbers to our computer’s memory first. we can do that with help of “variable”.</p><h3>variable means — liable to change</h3><h3>Whats is a variable in Programming 🤔?</h3><blockquote>In programming, <strong>variables</strong> are containers which hold reusable data(variable can be thought of as a memory location that can hold values of a specific data type).</blockquote><blockquote>OK. Now let’s see how we can <strong>declare(</strong>saying that it is a variable to compiler<strong>) </strong>a variable in JavaScript?</blockquote><p>There are three ways to define a variable in JavaScript.</p><ul><li>using <strong>var </strong>keyword.</li><li>using <strong>let </strong>keyword.</li><li>using <strong>const </strong>keyword.</li></ul><blockquote>&lt;Keyword&gt; &lt;variable_name&gt; = &lt;value&gt;</blockquote><h4>I got you. Now you’re thinking, what’s a keyword?</h4><p>In Programming languages, <strong>Keywords </strong>are<strong> </strong>special words which are reserved by the programming language in which your’e writing programs.It means we can’t use a key word as a variable.</p><p>Check out the list of JavaScript keywords <a href="https://www.w3schools.com/js/js_reserved.asp">here</a></p><h3>Rules for naming JavaScript variables</h3><ul><li>Variable names cannot contain spaces.</li><li>Variable names must begin with a letter, an underscore _ or a dollar sign $.</li><li>Variable names can only contain letters, numbers, underscores, or dollar signs.</li><li>Variable names are case-sensitive</li><li>keywords can’t be used variable name.</li></ul><p>lets <strong>define </strong>a variable in VS code and see what happens in output console (browser developer tools).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*teHU_4PMYKtzk8S1OtCBWA.png" /><figcaption>Our first Variable🎉</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*haTSs7_PQHr7D38nWqiO2A.png" /><figcaption>Defining our first variable in JavaScript🖤</figcaption></figure><p>Nothings shows up in browser right😔.Hey Don’t worry 😉 that’s expected. Now let’s break the code and discuss what we did and what happened inside our computer💻.</p><p>We just <strong>defined</strong> a variable but we can also <strong>declare(also known as initialization)</strong> a variable without mentioning the value of it.Confusing 🤔? OK let’s discuss what is <strong>defining a variable</strong> and <strong>declaring a variable</strong>.</p><h3>Variable — Declaration(Initialization) vs Definition</h3><h4>Declaration</h4><p><strong>Declaration</strong> of a variable is for informing to the compiler(browser in our case) the following:</p><ul><li>Name of the variable.</li><li>Datatype of the variable</li></ul><p>JavaScript is <strong>dynamically typed</strong> which means the data type of the variable is determined by compiler over time😧.</p><p>So we need not declare a datatype🤩 rather we use three keywords which i mentioned above to declare a variable in JavaScript.</p><h4>what is a data type 🙄?</h4><p>Data types are used to classify one particular type of data from another in programming languages.</p><p>for example:</p><p>To store a number it takes some amount of storage in our container. i.e.,variable</p><p>To store a long string (set of characters), it takes different amount of storage.</p><blockquote>so we have different <strong>data types</strong> to store different data in our container.Our next post is all about data types.</blockquote><p>In JavaScript we need not to mention data types. But it’s better to have the understanding of how data get stored in a computer <strong>to become a better programmer or developer</strong> who is good at tackling problems, when something bad happens to our application or program.</p><p>we will discuss the in depth details of data types in next post</p><blockquote>In statically typed programming languages like c,c++,java we need to mention the data type before the variable name.</blockquote><p>You can understand the pros and cons of Statically typed languages and dynamically typed programming languages by reading the post below👇</p><p><a href="https://medium.com/hackernoon/statically-typed-vs-dynamically-typed-languages-e4778e1ca55">Statically typed vs dynamically typed languages</a></p><p>let’s declare variable using JavaScript</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*VwzDjgelnn7gq7rzI3w1hw.png" /><figcaption>Declaring variable in JavaScript</figcaption></figure><h4>what happens when we declare variable 🤔?</h4><p>JavaScript compiler sets variable’s value as <strong>undefined.</strong>because we didn’t mention any data type when we declared that variable.</p><p><strong>Undefined</strong> is also a data type in JavaScript.</p><p>let’s see that in action😁</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pAH6NZfZuJqYhZ3_B7Le3w.png" /></figure><p>You can see that console have some output printed on it🎉.In main.js line:2 <strong>undefined.</strong></p><blockquote>console.log() is a magic 😜 which is used to print values to console(Browser’s console).We will discuss about it, when we discuss function(which is a programming concept)</blockquote><h4>what happens when we define a variable 🤔?</h4><p>Now,the JavaScript compiler will guess the data type and assign our variable a data type.</p><p>Compiler also allocates memory for the variable which we just defined.Every datatype has it own memory size.We mention the size of memory in <strong>bytes(unit of measurement in computer terms).</strong></p><p>let’s see that in action😁</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JaYO_7VpLHAap1KPKh0ung.png" /></figure><p>when we defined the <strong>cow </strong>variable as ‘🐄’ the compiler guessed the data type and assigned the memory in our computers RAM(also called as primary memory).when the next line console.log(cow) is called rather than printing <strong>undefined </strong>it prints the value stored inside the variable 🎉.</p><p>Here the cow emoji ‘🐄’ is guessed as <strong>string</strong> data type ,then the compiler assigns memory required for string and stores the cow emoji in it.Now we can call the variable cow to access the stored emoji ‘🐄’. As like we did in the above screenshot👆.</p><p>I’m just using <strong>var </strong>keyword to define and declare variables.But i mentioned we can also use<strong> let</strong> and <strong>const.</strong></p><blockquote>we will discuss about other two keywords and difference between <strong>var </strong>vs <strong>let </strong>vs <strong>const </strong>in a separate upcoming medium post.</blockquote><p>Happy coding 🎉 and Have a nice day🎊</p><p>Up next what is a data type in programming?🤩</p><blockquote>Don’t forget to applause if you found it helpful😜</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=189802256650" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>