<?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: Coder Pink</title>
    <description>The latest articles on DEV Community by Coder Pink (@coderpink).</description>
    <link>https://dev.to/coderpink</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%2F854258%2Fadb4ab30-c0fa-4c15-af17-cee789d1ad4a.jpeg</url>
      <title>DEV Community: Coder Pink</title>
      <link>https://dev.to/coderpink</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coderpink"/>
    <language>en</language>
    <item>
      <title>CSS interview question and answer in brief.</title>
      <dc:creator>Coder Pink</dc:creator>
      <pubDate>Thu, 06 Mar 2025 09:52:54 +0000</pubDate>
      <link>https://dev.to/coderpink/css-interview-question-and-answer-in-brief-1i6b</link>
      <guid>https://dev.to/coderpink/css-interview-question-and-answer-in-brief-1i6b</guid>
      <description>&lt;p&gt;As a web developer, understanding CSS is very essential. CSS (Cascading Style Sheets) is the language used to style and format the layout of web pages. In this blog, we'll explore some common CSS interview questions and their answers to help you ace your next interview. These questions not only test your knowledge but also assess how well you can apply CSS in real-world situations.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What is the difference between class and id selectors in CSS?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Class:&lt;/strong&gt; A class selector targets elements that share the same class attribute. Multiple elements can have the same class, and a class can be used more than once in the CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.example { color: blue; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;id: An ID selector is unique and targets only one element with that specific ID. It can only be used once per page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#example { color: red; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  2. What is the box model in CSS?
&lt;/h2&gt;

&lt;p&gt;The CSS box model describes the rectangular boxes generated for elements on a web page. Each box consists of four areas:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Content:&lt;/strong&gt; The actual content of the element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Padding:&lt;/strong&gt; Clears an area around the content (inside the border).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Border:&lt;/strong&gt; A border surrounding the padding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Margin:&lt;/strong&gt; Clears an area outside the border, creating space between elements.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  3.  Explain the difference between inline, block, and inline-block elements.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;inline:&lt;/strong&gt; The element does not start on a new line and only takes up as much width as necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;block:&lt;/strong&gt; The element starts on a new line and takes up the full width of its container.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;inline-block:&lt;/strong&gt; Combines both behaviors: the element is inline but also respects width and height properties.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. What is the difference between em, rem, and px units in CSS?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;px:&lt;/strong&gt; A fixed-size unit, relative to the resolution of the display.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;em:&lt;/strong&gt; A relative unit that depends on the font size of the element itself or its parent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;rem:&lt;/strong&gt; A relative unit, but it depends on the root element’s font size, making it more predictable than em.&lt;/p&gt;




&lt;h2&gt;
  
  
  5.  What are CSS pseudo-classes and pseudo-elements?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pseudo-classes:&lt;/em&gt;&lt;/strong&gt; Used to define the special state of an element. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;:hover:&lt;/strong&gt; Applied when the user hovers over an element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;:focus:&lt;/strong&gt; Applied when an element gains focus. %}&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pseudo-elements:&lt;/em&gt;&lt;/strong&gt; Used to style specific parts of an element. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;::before: Inserts content before an element.&lt;/li&gt;
&lt;li&gt;::after: Inserts content after an element.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  6. What are the different types of CSS positioning?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;static:&lt;/strong&gt; Default positioning, elements are positioned according to the normal document flow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;relative:&lt;/strong&gt; Elements are positioned relative to their normal position.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;absolute:&lt;/strong&gt; Positioned relative to the nearest positioned ancestor (not static).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;fixed:&lt;/strong&gt; Positioned relative to the viewport, meaning it stays in place even when the page is scrolled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;sticky:&lt;/strong&gt; Acts like relative until it reaches a defined scroll position, then it behaves like fixed.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. What is Flexbox and how does it work?
&lt;/h2&gt;

&lt;p&gt;Flexbox is a layout model that allows for the easy arrangement of elements within a container. It enables you to align items horizontally or vertically with ease.&lt;/p&gt;

&lt;p&gt;Key properties include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;display:&lt;/strong&gt; flex on the container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;justify-content&lt;/strong&gt; to align items horizontally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;align-items&lt;/strong&gt; to align items vertically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;flex&lt;/strong&gt; on items to control their growth and shrinkage within the container.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. What are media queries and how do they work?
&lt;/h2&gt;

&lt;p&gt;Media queries allow you to apply different styles to elements based on the characteristics of the device (e.g., screen width, height, orientation, print). Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@media (max-width: 768px) {
  body { background-color: lightblue; }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This will change the background color of the body element on devices with a screen width of 768px or less&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  11. How can you create a responsive design using CSS?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use flexible grids or Flexbox for layout.&lt;/li&gt;
&lt;li&gt;Apply relative units like em, rem, % instead of fixed units like px.&lt;/li&gt;
&lt;li&gt;Utilize media queries to adjust styles based on different screen sizes.&lt;/li&gt;
&lt;li&gt;Ensure that images are responsive using max-width: 100% to prevent overflow.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  12.  What is the z-index property and how does it work?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;z-index&lt;/strong&gt; property controls the stacking order of elements. Elements with a higher z-index are stacked in front of elements with a lower z-index. It only works on positioned elements (those with position: relative, absolute, fixed, or sticky).&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>css</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript Strings and String Methods as a Beginners you should know</title>
      <dc:creator>Coder Pink</dc:creator>
      <pubDate>Wed, 03 Jan 2024 06:07:16 +0000</pubDate>
      <link>https://dev.to/coderpink/javascript-strings-and-string-methods-as-a-beginners-you-should-know-2ckc</link>
      <guid>https://dev.to/coderpink/javascript-strings-and-string-methods-as-a-beginners-you-should-know-2ckc</guid>
      <description>&lt;h2&gt;
  
  
  String:
&lt;/h2&gt;

&lt;p&gt;String is basically a sequence of characters that is used for storing and managing text data. JavaScript String is primitive data types and are immutable(means you cannot change the original string).There are two ways to create a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using String Literals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let name = "Hello World";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;here you have to enclosed the text inside the double or single quotes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using String Object&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let name = new String("Hello World");&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  String Methods :
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;charAt Method:&lt;/strong&gt; returns the character from a specified index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name = "Hello World";
let value = name.charAt(1);
console.log(value);
//value = e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;concat method:&lt;/strong&gt; Join two or more string together&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str = "Hello ";
let str1 = "World";
let total = str.concat(str1);
console.log(total);
//total = Hello World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;replace method:&lt;/strong&gt; replace the given string with specified replacement values&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str = "Your name";
let replaceValue = str.replace("Your", "My");
console.log(replaceValue);
//My name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;search method:&lt;/strong&gt; It searches a string against a specified values or regular expressions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let text = "Please keep quiet!";
console.log(text.search("keep"));
console.log(text.search(/quiet/));
// 7
//12
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;note:&lt;/em&gt; it will return the first occurrence of the string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;indexOf method:&lt;/strong&gt; It return the index of first occurrence of the string. It cannot take regular expression values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let text = "Move ahead!";
let index = text.indexOf("ahead");
console.log(index);
//5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;split method:&lt;/strong&gt; convert a string into array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let text = "Move ahead!";
let value = text.split(" ");
console.log(value);

//[ 'Move', 'ahead!' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;slice method:&lt;/strong&gt;  extracts a part of a string and returns the extracted part in a new string.&lt;br&gt;
it takes start position and end position(not included) in parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let text = "Move ahead!";
let value = text.slice(6, 10);
console.log(value);

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Hope you find this helpful&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Learn Ajax in simple way for Beginners (part - a)</title>
      <dc:creator>Coder Pink</dc:creator>
      <pubDate>Tue, 04 Apr 2023 05:51:15 +0000</pubDate>
      <link>https://dev.to/coderpink/learn-ajax-in-simple-way-for-beginners-part-a-4dc0</link>
      <guid>https://dev.to/coderpink/learn-ajax-in-simple-way-for-beginners-part-a-4dc0</guid>
      <description>&lt;h2&gt;
  
  
  So Here is our question arise what is ajax and how it is work?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ajax stands for &lt;em&gt;Asynchronous  JavaScript and XML&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ajax is used  to exchange  data  with a  web server &lt;br&gt;
asynchronously.&lt;em&gt;(asynchronously means  it send and receive data in background and do not reload the page every time in doing so)&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The reason ajax  is famous, for it only change the parts of the page which we are updating or changing instead of reloading the whole web page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ajax support &lt;em&gt;non-blocking calls&lt;/em&gt; means codes can run simultaneously.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When we are  using ajax , JavaScript will make a request to the server and after getting response from server, it will interpret the response and update or  show the result on the user  screen.&lt;/p&gt;

&lt;p&gt;ajax asynchronously communicate with server using &lt;em&gt;XMLHttpRequest&lt;/em&gt;.&lt;br&gt;
example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let ajaxXhr  = new XMLHttpRequest();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here XMLHttpRequest() is object request we have  created and stored  it in variable name ajaxXhr.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How ajax Works :&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When an event(means like a user  click a button, hover a mouse etc.) occurred on a webpage. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;then this awakes the ajax engine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ajax engine send the XMLHttpRequest to the server. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;then server give the response to the ajax engine in the format of JSON or XML. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;after getting the response it will update the webpage(not whole).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;easy example of ajax running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;btn.addEventListener("click", ajaxRun);

function ajaxRun(){
let xhr = new XMLHttpRequest();
xhr.open("GET", "file.txt", true);
xhr.send();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from above example, we add a event listener to button (btn), means when we click btn , it will run ajaxRun function.&lt;br&gt;
in ajaxRun function, it will create a &lt;em&gt;new XMLHttpRequest()&lt;/em&gt; object,&lt;br&gt;
and store it in xhr variable.&lt;br&gt;
then we use object method on xhr for further action.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;we use open method in which we have three parameter &lt;br&gt;
open(method, URL , async) i.e it tells where we are transmitting the data. (talk about detail in next part).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;send method tells us that the request is send.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use of Ajax :&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;it is used for creating dynamic Web apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;with ajax, we can send and receive data without reloading the webpage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It makes our web apps interactive and faster &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Hope it help... we talk about it more in ajax part-b&lt;/code&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>ajax</category>
    </item>
    <item>
      <title>Things to know as a Beginner in JSON.</title>
      <dc:creator>Coder Pink</dc:creator>
      <pubDate>Fri, 03 Feb 2023 17:27:17 +0000</pubDate>
      <link>https://dev.to/coderpink/things-to-know-as-a-beginner-in-json-4fec</link>
      <guid>https://dev.to/coderpink/things-to-know-as-a-beginner-in-json-4fec</guid>
      <description>&lt;h2&gt;
  
  
  Things to remember...
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;JSON stands for JavaScript Object Notation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JSON is very lightweight as compared to XML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is text format for storing and retrieving data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is human readable and easy to understand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is very good to use JSON rather than XML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;With JSON, can easily integrate with JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The file type for JSON files is ".json"&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;example of JSON...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'{"name":"Tae", "age":26, "bike":null, "isGood" : true}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in the above example, we can see that JSON is like an object that has key-value pairs. you have to enclose the JSON object with backticks(``).&lt;/p&gt;

&lt;p&gt;It can take  values as numbers, strings, null, Boolean, array and object.&lt;br&gt;
You can also store an array in array, object in arrays as long as it is readable.&lt;/p&gt;

&lt;p&gt;``&lt;br&gt;
&lt;/p&gt;

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

newJson = '{"name":"Tae", "age":26, "bike":null, "isGood" : true}'

//'{"name":"Tae", "age":26, "bike":null, "isGood" : true}'

parsedJson = JSON.parse(newJson)

// {name: 'Tae', age: 26, bike: null, isGood: true}

parsedJson['age']

//26

parsedJson["isGood"]

//true


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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
``&lt;/p&gt;

&lt;p&gt;Store json object in new variable named newJson.&lt;/p&gt;

&lt;p&gt;parse the jSON object so that you will get the JavaScript object and can access JavaScript object.&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>ethereum</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Scope in JavaScript (Block Scope and Function Scope)</title>
      <dc:creator>Coder Pink</dc:creator>
      <pubDate>Mon, 05 Sep 2022 08:56:50 +0000</pubDate>
      <link>https://dev.to/coderpink/scope-in-javascript-block-scope-and-function-scope-eg7</link>
      <guid>https://dev.to/coderpink/scope-in-javascript-block-scope-and-function-scope-eg7</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.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%2Fjvhx5ajbn8pl8flo1v26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjvhx5ajbn8pl8flo1v26.png" alt=" " width="225" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Scope... Scope determines the accessibility of variables.
&lt;/h4&gt;

&lt;p&gt;In JavaScript we'll create variable with var, let, and const keyword. they will create scope, that means we can only access the variable within the scope.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block Scope:&lt;/strong&gt;  &lt;em&gt;let&lt;/em&gt; and &lt;em&gt;const&lt;/em&gt; create Block Scope. When we create a variable with &lt;em&gt;let&lt;/em&gt; and &lt;em&gt;const&lt;/em&gt;, they will create &lt;strong&gt;block scope&lt;/strong&gt; means they can only access the block they are declared or created in. &lt;/p&gt;

&lt;p&gt;So let's take a look at the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (true) {
    let one = "one";
    console.log(one); // "one"
}

console.log(one); // Uncaught Reference Error: one is not defined

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

&lt;/div&gt;



&lt;p&gt;From the above example... we can see that we get an error when we console.log to the variable one outside the if statement.&lt;br&gt;
Because variable one is declared within the if statement... its scope is only limited to the if statement. and we cannot access the let one outside the if statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Function Scope:&lt;/strong&gt;  Variable that are declared inside of a function will create a &lt;em&gt;function scope&lt;/em&gt;. this means you can only access the value within the function there or the parent function.&lt;/p&gt;

&lt;p&gt;Let's take a look at the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fun(b) {
  var a = 12;
  return a + b;
}

fun(5);// 17  fun is being called
console.log(a); // Uncaught Reference Error: a is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the above example...  we can see that we get an error when we were trying to access the variable a outside the function that says a is not defined as we read above. &lt;br&gt;
So remember when you put or declared a variable inside the function, then it is only local to that function.&lt;/p&gt;

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