<?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: Pratiyush Kumar</title>
    <description>The latest articles on DEV Community by Pratiyush Kumar (@mein_pk_hoon_pk).</description>
    <link>https://dev.to/mein_pk_hoon_pk</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%2F682199%2Fde527a9c-97d8-46c9-9e6d-1195fbe1acf4.jpg</url>
      <title>DEV Community: Pratiyush Kumar</title>
      <link>https://dev.to/mein_pk_hoon_pk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mein_pk_hoon_pk"/>
    <language>en</language>
    <item>
      <title>Block in JS part-2</title>
      <dc:creator>Pratiyush Kumar</dc:creator>
      <pubDate>Wed, 29 Sep 2021 17:30:41 +0000</pubDate>
      <link>https://dev.to/mein_pk_hoon_pk/block-in-js-part-2-bg0</link>
      <guid>https://dev.to/mein_pk_hoon_pk/block-in-js-part-2-bg0</guid>
      <description>&lt;p&gt;Hello Folks, I am back with the part2 of block where I will share next part of block. In previous blog we saw what do we mean by block now we will see what is block scope.&lt;/p&gt;

&lt;p&gt;Block Scope means whatever variables and functions are defined inside a block, they have access inside block itself. They can not be accessed outside of the block.&lt;/p&gt;

&lt;p&gt;Below is example to show that variables inside block is getting accessed.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jUEtew3M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewqt0ut3ltitgzc8pzw6.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jUEtew3M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ewqt0ut3ltitgzc8pzw6.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;output is below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vhgnPUkC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3og6mn1ej5dsxlcjm6n.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vhgnPUkC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3og6mn1ej5dsxlcjm6n.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we try to access variables outside the block then you will only variable which was defined with var can be accessed outside the block because var is global scoped while let and const variables are blocked scoped.&lt;/p&gt;

&lt;p&gt;Thus this proves that let and const variables are blocked scope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---wSdrYbU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwpuoyxcao9t7kpx1gea.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---wSdrYbU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwpuoyxcao9t7kpx1gea.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qdTggTdj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d98cpd2d52liqvx3304x.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qdTggTdj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d98cpd2d52liqvx3304x.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hence you can see if we try to access the let and const variable outside the variable it will give error as "uncaught ReferenceError: b is not defined". &lt;/p&gt;

&lt;p&gt;Above we talk about block scope where we saw the scope of variable inside the block but what about the functional scope. &lt;/p&gt;

&lt;p&gt;Inside function every variable is function scoped i.e. variables can be accessed only inside the function and not outside the fucntion.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r2mtjb-E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wd0reqki7q239uefw3ip.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r2mtjb-E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wd0reqki7q239uefw3ip.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ncaP_25t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4f4r3jho9xua028ovbge.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ncaP_25t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4f4r3jho9xua028ovbge.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but when we try to access a variable inside a function that is defined outside the function we can access the variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W8mfGjk4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vu412d9dle8imaslmnwk.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W8mfGjk4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vu412d9dle8imaslmnwk.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u57XLjGd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ea6bc2qgqa4nkdhzt0sb.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u57XLjGd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ea6bc2qgqa4nkdhzt0sb.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Block in JS  part-1</title>
      <dc:creator>Pratiyush Kumar</dc:creator>
      <pubDate>Mon, 20 Sep 2021 19:38:34 +0000</pubDate>
      <link>https://dev.to/mein_pk_hoon_pk/block-in-js-part-1-46mf</link>
      <guid>https://dev.to/mein_pk_hoon_pk/block-in-js-part-1-46mf</guid>
      <description>&lt;p&gt;Hello Folks, Hope you are doing good. This is my first blog on javascript. I hope You find my blog interesting. If you find something wrong, please provide suggestions in the comment box. &lt;/p&gt;

&lt;p&gt;This is the part1 of the blog on block. Soon part2 of the blog will come which will cover block scope and shadowing in JS.&lt;/p&gt;

&lt;p&gt;Let's discuss the topic-&lt;/p&gt;

&lt;p&gt;Frist of all we need to learn what is the block in JS. Many a times when people are asked about the block in JS, first thought they get in mind is that block is related to let and const concept. let and const are bloced scoped but they have nothing to in this topic. &lt;/p&gt;

&lt;p&gt;Block is also known as "Compound statement". When we write a code, JS accepts one line code.when we combine multiple line of code into the block, JS treats that as single line code.&lt;/p&gt;

&lt;p&gt;Suppose we need to just console single line we would have just written in following way:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RTOsnl8q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zobb77k71l8crb1uf8m5.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RTOsnl8q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zobb77k71l8crb1uf8m5.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, if we needed to print the value of "a" only, if loop was true then:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lp7zRCby--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uh0shszijlbujermrce2.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lp7zRCby--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uh0shszijlbujermrce2.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basic syntax of for loop or if loop is same as mentioned below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PE1v5co9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hpvzsjosmuie6um2s72j.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PE1v5co9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hpvzsjosmuie6um2s72j.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but if we want to use multiple lines inside if or for loop then we need to use block.&lt;/p&gt;

&lt;p&gt;Basically block are commonly used in for loop, if loop, if...else loop, functions, etc.&lt;/p&gt;

&lt;p&gt;javaScript basically accepts single line at a time but to make javaScript accept the multiple line, we combine them into a block.&lt;/p&gt;

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