<?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: Sahiba Kumari</title>
    <description>The latest articles on DEV Community by Sahiba Kumari (@sahiba0915).</description>
    <link>https://dev.to/sahiba0915</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%2F689609%2Ff8feffd3-8372-4fd6-af62-9b1ada346bd5.jpeg</url>
      <title>DEV Community: Sahiba Kumari</title>
      <link>https://dev.to/sahiba0915</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sahiba0915"/>
    <language>en</language>
    <item>
      <title>Nullish Coalescing Operator(??)</title>
      <dc:creator>Sahiba Kumari</dc:creator>
      <pubDate>Fri, 03 Jun 2022 16:07:36 +0000</pubDate>
      <link>https://dev.to/sahiba0915/nullish-coalescing-operator-452i</link>
      <guid>https://dev.to/sahiba0915/nullish-coalescing-operator-452i</guid>
      <description>&lt;p&gt;Hello everyone so today I'll write about &lt;strong&gt;&lt;em&gt;Nullish Coalescing Operator&lt;/em&gt;&lt;/strong&gt; .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nullish Coalescing Operator&lt;/strong&gt; is a logical operator that returns the left-hand operand as the result or returns the right-hand side operand when the left-hand side operand is null or undefined.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;leftExpression ?? rightExpression
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a = null ?? 'hello neogrammer';
console.log(a); // output: hello neogrammer

const b = 'hi' ?? 'hello'
console.log(b); //output: hi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if you run the above examples you can see that the value of &lt;strong&gt;&lt;em&gt;"a"&lt;/em&gt;&lt;/strong&gt; will be &lt;strong&gt;&lt;em&gt;"hello neogrammer"&lt;/em&gt;&lt;/strong&gt; as the left-hand operand is null.&lt;br&gt;
While in the second example value of &lt;strong&gt;&lt;em&gt;"b"&lt;/em&gt;&lt;/strong&gt; will be &lt;strong&gt;&lt;em&gt;"hi"&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
as the right hand value is now not null or undefined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Why Nullish Coalescing Operator???&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As we know we were having &lt;strong&gt;&lt;em&gt;OR&lt;/em&gt;&lt;/strong&gt; operator for this kind of operations but there was as an issue with this operator as being a Boolean logical operator, the left hand operand is forced to a boolean for the evaluation and any falsy values like 0, NaN, "", null, undefined was not returned, and this may cause issues for you if you consider these falsy values as valid values.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

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

const result = c || 50 ;
console.log(result); //output: 50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the output will be &lt;strong&gt;&lt;em&gt;50&lt;/em&gt;&lt;/strong&gt; not &lt;strong&gt;&lt;em&gt;0&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;To overcome this issue Nullish Coalescing Operator comes into the picture, this operator works well with falsy values unlike  &lt;strong&gt;&lt;em&gt;OR&lt;/em&gt;&lt;/strong&gt; operand.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

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

const res = d || 'hii programmers' //output: hii programmers
const res2 = d ?? 'hii everyone' //output: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, if you run the above example you'll see that we have taken 0 (a falsy value) and the &lt;strong&gt;&lt;em&gt;OR&lt;/em&gt;&lt;/strong&gt; operand is not accepting the falsy value and returning the second operand while the &lt;strong&gt;&lt;em&gt;Nullish Coalescing Operator&lt;/em&gt;&lt;/strong&gt; works fine with the falsy value and returns 0.&lt;/p&gt;

&lt;p&gt;So, in short if you want to work with these kinds of falsy values you can use this amazing operator.&lt;/p&gt;

&lt;p&gt;Thank you.&lt;br&gt;
Happy Learning!!!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Temporal Dead Zone</title>
      <dc:creator>Sahiba Kumari</dc:creator>
      <pubDate>Fri, 14 Jan 2022 14:53:15 +0000</pubDate>
      <link>https://dev.to/sahiba0915/temporal-dead-zone-1ahe</link>
      <guid>https://dev.to/sahiba0915/temporal-dead-zone-1ahe</guid>
      <description>&lt;p&gt;&lt;em&gt;Hello Everyone, So today I'll talk about the** Temporal dead Zone** in JavaScript.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temporal Dead Zone(TDZ)&lt;/strong&gt; is basically refers to the duration between a variable declaration and it's initialization. TDZ occurs when we use &lt;strong&gt;const&lt;/strong&gt; and &lt;strong&gt;let&lt;/strong&gt; for declaring our variables.&lt;/p&gt;

&lt;p&gt;Let's look into some of the examples that explains this concept.&lt;/p&gt;

&lt;p&gt;This concept of &lt;strong&gt;TDZ&lt;/strong&gt; in JavaScript comes from the concept of hoisting let &amp;amp; const variables.&lt;br&gt;
Like var, let &amp;amp; const are also hoisted but in a different way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hoisting example for var:
console.log(a); //undefined no error
var a = 10; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Here in the above examples explains the concept that no matter your variable after declaration is being initialized or not, it will get a value of undefined during execution if you haven't assigned that variable.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hoisting example for let variables:
console.log(b); 
let b = 20;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Here in the above example you'll get a reference error, this is because a let variable is being allocated memory in separate space [unlike var variable that is being allocated memory in the global object (i.e; the window object)] which we can't access until we assign some value to that variable. That means let variables can't be accessed until assigned some value to it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Same goes with the const variables also if you try to access them before initialization it will throw a reference error.&lt;/p&gt;

&lt;p&gt;So, the basic idea is let and const variables remains in TDZ until it gets some value assigned to it, once the initialization is done TDZ ends for that specific variable.&lt;/p&gt;

&lt;p&gt;Tip: To avoid TDZ always try move all your declaration and initialization part to the top of your program so that before the main logic the execution hits the initialization part.&lt;/p&gt;

&lt;p&gt;So, that's it for this time. I hope I made the points clear.&lt;br&gt;
Thank you!!!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy Reading!!!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>var Vs let Vs const</title>
      <dc:creator>Sahiba Kumari</dc:creator>
      <pubDate>Fri, 03 Sep 2021 15:29:39 +0000</pubDate>
      <link>https://dev.to/sahiba0915/var-vs-let-vs-const-352k</link>
      <guid>https://dev.to/sahiba0915/var-vs-let-vs-const-352k</guid>
      <description>&lt;p&gt;&lt;em&gt;Hello everyone!!!!&lt;/em&gt;!&lt;/p&gt;

&lt;p&gt;This time I'll discuss about the difference between the basic three types of variable in JavaScript var , const and let. Basically I'll discuss about the three major difference between them i.e.; &lt;strong&gt;their scope, their reassigning and redeclaration and their hoisting.&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;var&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;1. Scope :&lt;/strong&gt; var if used inside a function then it is said to be function scoped or locally scoped variable but if it is used outside any function it is said to be globally scoped variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var msgOne="Good morning";

function greet () {
var msgTwo= "Good day";
}

console.log(msgTwo);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;So, if you will run the above example you'll get an error msg that the msgTwo is not defined, this is because the msgTwo variable is defined and declared inside a function and is non accessible outside that function greet().&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. Reassigning and Redeclaration :&lt;/strong&gt; This variable can be reassigned or redeclared within the same scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function welcome(){
var message = "hii";
var message = "hello";
 console.log(message);
}
welcome();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In the above example, you can see that if you'll run this piece of code you'll get the message as hello ,this shows that the var variable can be redeclared and reassigned within same scope.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Hoisting:&lt;/strong&gt; var variables are hoisted at the top of their scope before the code execution and also is initialized with a value undefined.&lt;/p&gt;

&lt;h1&gt;let&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;1. Scope :&lt;/strong&gt; let is also a blocked scoped variable that is non accessible outside that block i.e.; the curly brackets {}.&lt;br&gt;
&lt;/p&gt;

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

if( count &amp;lt; 5){
let output = "hello";
console.log(output);
}

console.log(output);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;So, if you will run the above example you'll get an error msg at line number 8 that output is not defined, this is because the output variable is defined and declared inside a block and is non accessible outside that block.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. Reassigning and Redeclaration :&lt;/strong&gt; This variable can be reassigned but cannot be redeclared.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function number(){
let digit = "hii";
digit = "hello";
console.log(digit);
}
number();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function draw(){
let art = "hii";
let art = "hello";
console.log(art);
}
draw();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In the above example, you can see that if you'll run the first piece of code you'll get the digit as hello , this shows that the let variable can be reassigned, but if you'll run the second piece of code&lt;br&gt;
you'll get an error that identifier "art" is also declared , this shows that let cannot be redeclared.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Hoisting:&lt;/strong&gt; let variables are also hoisted at the top of their scope before the code execution but are not initialized with any value like var.&lt;/p&gt;

&lt;h1&gt;const&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;1. Scope :&lt;/strong&gt; const is a blocked scoped variable that is non accessible outside that block i.e.; the curly brackets {}.&lt;br&gt;
&lt;/p&gt;

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

if( count &amp;lt; 5){
const output = "hello";
console.log(output);
}

console.log(output);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;So, if you will run the above example you'll get an error msg at line number 8 that output is not defined, this is because the output variable is defined and declared inside a block and is non accessible outside that block.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. Reassigning and Redeclaration :&lt;/strong&gt; This variable can neither be redeclared nor reassigned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function welcome(){
const message = "hii";
const message = "hello";
console.log(message);
}
welcome();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function draw(){
const art = "hii";
art = "hello";
console.log(art);
}
draw();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In the above example, you can see that if you'll run this piece of code you'll get the message as the the identifier message has been already declared ,this shows that the const variable cannot be redeclared and if you run the second piece of code you'll get an error that assignment to constant variable error, this shows that it cannot be reassigned as well.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Hoisting:&lt;/strong&gt; const variables are hoisted at the top of their scope before the code execution but are not initialized with any value like var.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy Reading!!!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
