<?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: Vijay SRJ</title>
    <description>The latest articles on DEV Community by Vijay SRJ (@vijaysrj).</description>
    <link>https://dev.to/vijaysrj</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%2F380703%2F267397c5-15c5-4cb9-8fe2-12d51ee58db0.jpg</url>
      <title>DEV Community: Vijay SRJ</title>
      <link>https://dev.to/vijaysrj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vijaysrj"/>
    <language>en</language>
    <item>
      <title>An intro to Reactive programming in Spring Boot</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Fri, 01 Jul 2022 12:45:27 +0000</pubDate>
      <link>https://dev.to/vijaysrj/an-intro-to-reactive-programming-in-spring-boot-46c3</link>
      <guid>https://dev.to/vijaysrj/an-intro-to-reactive-programming-in-spring-boot-46c3</guid>
      <description>&lt;p&gt;An ebook with an introduction to reactive programming in Spring Boot.&lt;/p&gt;

&lt;p&gt;Programming comes in different paradigms.&lt;br&gt;
For long, we did procedural programming using languages like C where the business logic was executed step by step in a procedural manner. Then came Object Oriented Programming where you modelled your business requirement into domain objects. It represented real world more closely and has been quite successful even now. &lt;br&gt;
And we also have Functional programming, Event Driven programming etc.&lt;br&gt;
The latest among these is Reactive Programming.&lt;/p&gt;

&lt;p&gt;Reactive programming is non-blocking, asynchronous , deals with data streams and supports backpressure. &lt;/p&gt;

&lt;p&gt;This ebook gives a quick intro to Reactive Programming in Spring Boot with sample demo in both Spring Boot and Javascript.&lt;/p&gt;

&lt;p&gt;Contents:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reactive programming – definition&lt;/li&gt;
&lt;li&gt;Reactive programming in Spring Boot&lt;/li&gt;
&lt;li&gt;How to create a reactive REST API – demo&lt;/li&gt;
&lt;li&gt;How to consume a reactive REST API – demo&lt;/li&gt;
&lt;li&gt;Backpressure&lt;/li&gt;
&lt;li&gt;How to consume a reactive REST API in Javascript - demo&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;li&gt;Further Reading&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://vijaysrj.gumroad.com/l/springreactive"&gt;An Intro to Reactive Programming in Spring Boot&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Attribute vs Property in HTML</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Sat, 04 Dec 2021 10:14:42 +0000</pubDate>
      <link>https://dev.to/vijaysrj/attribute-vs-property-in-html-2l8a</link>
      <guid>https://dev.to/vijaysrj/attribute-vs-property-in-html-2l8a</guid>
      <description>&lt;p&gt;The terms attribute and property can be confusing in HTML.&lt;/p&gt;

&lt;p&gt;For example the javascript framework Angular has the concepts Property Binding and Attribute Binding . Without knowing the difference between the two it is difficult to grasp the difference between those concepts.&lt;/p&gt;

&lt;p&gt;The major difference between the two is this:&lt;/p&gt;

&lt;p&gt;Attribute is related to HTML&lt;/p&gt;

&lt;p&gt;Property is related to DOM&lt;/p&gt;

&lt;p&gt;Other differences:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Attribute and Property names are not always similar&lt;/li&gt;
&lt;li&gt;Changing Attribute/Property values doesn't always get reflected to the other&lt;/li&gt;
&lt;li&gt;Attribute is case sensitive , Property is not&lt;/li&gt;
&lt;li&gt;Attribute values are always strings , Property can be of different data types&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is an explanation with examples:&lt;br&gt;
&lt;a href="https://fullstackdeveloper.guru/2021/12/04/attribute-vs-property-in-html/"&gt;Attribute vs Property&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Published my first EBook on the Gang of Four Design Patterns in Java!</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Thu, 28 Oct 2021 13:49:32 +0000</pubDate>
      <link>https://dev.to/vijaysrj/published-my-first-ebook-24hb</link>
      <guid>https://dev.to/vijaysrj/published-my-first-ebook-24hb</guid>
      <description>&lt;p&gt;The Gang of Four Design Patterns are often hard to get .&lt;/p&gt;

&lt;p&gt;Most of the articles on the internet are generic or too complicated to understand. I wrote a book which solves this by providing an easier explanation of all the 23 design patterns with use cases implemented in Java and with link to GitHub.&lt;/p&gt;

&lt;p&gt;Every design pattern is presented with an use case , the solution in java and the link to Github.&lt;/p&gt;

&lt;p&gt;Once you finish this book , you will gain more confidence about implementing design patterns in your day to day programming.&lt;/p&gt;

&lt;p&gt;Link to the book : &lt;a href="https://vijaysrj.gumroad.com/l/designpatterns"&gt;The Gang of Four Design Patterns Simplified&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Topics covered:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creational :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deals with how to create objects.&lt;/p&gt;

&lt;p&gt;Singleton – Create a single instance of an object.&lt;/p&gt;

&lt;p&gt;Prototype– Use an existing object by cloning it.&lt;/p&gt;

&lt;p&gt;Factory Method – Delegate creation of an object to another object.&lt;/p&gt;

&lt;p&gt;Abstract Factory – Delegate creation of a group of related objects to another object.&lt;/p&gt;

&lt;p&gt;Builder – Delegate creation of a complex object to another object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structural:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deals with how to structure objects.&lt;/p&gt;

&lt;p&gt;Adapter – Make two incompatible interfaces work together.&lt;/p&gt;

&lt;p&gt;Bridge – Separate abstraction and implementation.&lt;/p&gt;

&lt;p&gt;Composite – Treat part-whole hierarchy the same way.&lt;/p&gt;

&lt;p&gt;Decorator – Add responsibilities to an object dynamically.&lt;/p&gt;

&lt;p&gt;Facade – Provide a single interface for a group of related operations.&lt;/p&gt;

&lt;p&gt;Flyweight – Reuse objects than creating new ones.&lt;/p&gt;

&lt;p&gt;Proxy – Protect access to an object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Behavioral&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deals with how to communicate between objects.&lt;/p&gt;

&lt;p&gt;Chain of Responsibility – Allow different objects to carry out a responsibility.&lt;/p&gt;

&lt;p&gt;Command – Encapsulate requests as separate objects.&lt;/p&gt;

&lt;p&gt;Mediator – Act as a broker for communication between objects.&lt;/p&gt;

&lt;p&gt;Template – Provide basic template of an algorithm to implement.&lt;/p&gt;

&lt;p&gt;Strategy – Encapsulate different algorithms using separate objects which can be chosen at run time.&lt;/p&gt;

&lt;p&gt;State – Encapsulate state specific behavior in a separate object.&lt;/p&gt;

&lt;p&gt;Observer – Intimate group of objects when a change occurs.&lt;/p&gt;

&lt;p&gt;Memento – Allow to revert an object’s state.&lt;/p&gt;

&lt;p&gt;Iterator – Provide a generic way to iterate through collection of objects.&lt;/p&gt;

&lt;p&gt;Interpreter – Represent a grammar using an object.&lt;/p&gt;

&lt;p&gt;Visitor – Add new responsibilities to an object without changing its existing behavior.&lt;/p&gt;

&lt;p&gt;Note : The original book by the Gang of Four was referred for these posts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;About the author:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I am Vijay , a full stack developer and a Tech Manager working in a multi national IT company. I have over 13 years of experience in the IT industry and have spent major part of my career working on Java and related technologies. In this book, I have tried to present the design patterns by the Gang of Four in a simplistic way yet not compromising on the quality of the content.&lt;/p&gt;

</description>
      <category>java</category>
      <category>designpatterns</category>
      <category>gangoffour</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java 17 features </title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Thu, 12 Aug 2021 16:55:56 +0000</pubDate>
      <link>https://dev.to/vijaysrj/java-17-features-g97</link>
      <guid>https://dev.to/vijaysrj/java-17-features-g97</guid>
      <description>&lt;p&gt;Java 17 features are finalized and sealed. As of this writing , it is going to be released next month (September 2021).&lt;/p&gt;

&lt;p&gt;Though there are around 14 new features introduced in this release , only two of them directly help developers and they should be aware of these.&lt;/p&gt;

&lt;p&gt;Those two are :&lt;/p&gt;

&lt;p&gt;Pattern Matching for Switch&lt;br&gt;
Sealed Classess&lt;br&gt;
Pattern Matching for Switch is introduced as a preview feature and it is one among the ongoing features released by the Java team in the pattern matching series.&lt;/p&gt;

&lt;p&gt;This is explained in detail here with examples :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fullstackdeveloper.guru/2021/08/11/pattern-matching-for-switch-java-17/"&gt;Pattern Matching for Switch&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sealed classes were introduced in Java 15 as a preview feature and have now become a permanent feature in Java 17.&lt;/p&gt;

&lt;p&gt;Here is a detailed explanation on this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fullstackdeveloper.guru/2020/06/19/sealed-classes-and-interfaces-in-java/"&gt;Sealed Classes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most of the remaining features are related to the JVM .&lt;/p&gt;

&lt;p&gt;Here is the full list :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://openjdk.java.net/projects/jdk/17/"&gt;https://openjdk.java.net/projects/jdk/17/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>java17</category>
    </item>
    <item>
      <title>What is a closure in Javascript?</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Wed, 05 May 2021 15:33:59 +0000</pubDate>
      <link>https://dev.to/vijaysrj/what-is-a-closure-in-javascript-4nb8</link>
      <guid>https://dev.to/vijaysrj/what-is-a-closure-in-javascript-4nb8</guid>
      <description>&lt;p&gt;Let’s say you declare a variable in javascript.&lt;/p&gt;

&lt;p&gt;What is the scope of this variable?&lt;/p&gt;

&lt;p&gt;It is the entire function in which it is declared.&lt;/p&gt;

&lt;p&gt;What if it is declared within a particular block ?&lt;/p&gt;

&lt;p&gt;Still it’s scope is the entire function in which it is declared.&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;function test(value){

     if(value==1){
             var temp = "Hello the value entered is 1";

          }
        alert(temp);       //you can access temp here!
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code even though the variable temp is declared inside the if block , the scope of the variable is the entire function test() , hence the alert statement will alert the value “Hello the value entered is 1” .&lt;/p&gt;

&lt;p&gt;But , this will work only if the value is 1 , if the value does not match , javascript will skip the initialization of the variable and you will get undefined for the variable ‘temp’.&lt;/p&gt;

&lt;p&gt;Let’s play a little more with scope of a variable.&lt;/p&gt;

&lt;p&gt;Now , lets say the above function returns another function which accesses the variable “value”:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function test(value){



    return function(){

        console.log(value);

        value++;

        return value;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now , does the returned function has access to the variable “value” once is it is returned.&lt;/p&gt;

&lt;p&gt;Like when you assign the returned function like this:&lt;/p&gt;

&lt;p&gt;var returnedfunction = test(5);&lt;br&gt;
and then you call the returned function:&lt;/p&gt;

&lt;p&gt;returnedfunction();&lt;br&gt;
Does the returnedfunction() now has access to the variable “value”?&lt;/p&gt;

&lt;p&gt;It does!&lt;/p&gt;

&lt;p&gt;The value of the variable “value” is incremented every time you call returnedfunction().&lt;/p&gt;

&lt;p&gt;I called it thrice in my code and it returned 5,6 and 7:&lt;br&gt;
&lt;/p&gt;

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

function test(value){



    return function(){

        console.log(value);

        value++;

        return value;
    }
}


var returnedfunction = test(5);

returnedfunction();

returnedfunction();

returnedfunction();


&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output was&lt;br&gt;
5&lt;br&gt;
6&lt;br&gt;
7&lt;br&gt;
This connection to the variable in its surrounding scope for the returned function + the returned function are together called a closure.&lt;/p&gt;

&lt;p&gt;Repeating it again :&lt;/p&gt;

&lt;p&gt;Closure = a function + its connection to variables in its surrounding scopes even after it leaves the scope where it was created&lt;/p&gt;

&lt;p&gt;That’s it!&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Javascript functions vs Java functions</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Tue, 04 May 2021 16:07:26 +0000</pubDate>
      <link>https://dev.to/vijaysrj/javascript-functions-vs-java-functions-329m</link>
      <guid>https://dev.to/vijaysrj/javascript-functions-vs-java-functions-329m</guid>
      <description>&lt;p&gt;A post on how javascript functions differ from Java functions. &lt;br&gt;
Would help java developers trying their hands on javascript :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You don’t specify the type of javascript parameters&lt;/li&gt;
&lt;li&gt;Javascript functions don’t need to live inside a Class&lt;/li&gt;
&lt;li&gt;Javascript functions can be assigned to a variable&lt;/li&gt;
&lt;li&gt;Javascript functions can be passed as parameters to other functions&lt;/li&gt;
&lt;li&gt;You can pass any number of parameters to a javascript function&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Explanation with samples :&lt;br&gt;
&lt;a href="https://fullstackdeveloper.guru/2021/05/04/how-do-javascript-functions-differ-from-java-functions/"&gt;https://fullstackdeveloper.guru/2021/05/04/how-do-javascript-functions-differ-from-java-functions/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>How does Number data type differ in Java and Javascript?</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Fri, 30 Apr 2021 11:26:10 +0000</pubDate>
      <link>https://dev.to/vijaysrj/how-does-number-data-type-differ-in-java-and-javascript-3g6d</link>
      <guid>https://dev.to/vijaysrj/how-does-number-data-type-differ-in-java-and-javascript-3g6d</guid>
      <description>&lt;p&gt;Brendan Eich , while creating Javascript took a great influence from Java. &lt;br&gt;
In fact he was asked to create the Java language on the browser by the company Netscape.&lt;/p&gt;

&lt;p&gt;So though Javascript has a lot of similarities with Java , it varies widely in other aspects.&lt;/p&gt;

&lt;p&gt;With respect to numbers , Javascript treats Numbers differently from Java in these ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;All numbers are floating point numbers in Javascript&lt;/li&gt;
&lt;li&gt;You can represent 'Not a Number' in Javascript&lt;/li&gt;
&lt;li&gt;You can represent Infinity in Javascript&lt;/li&gt;
&lt;li&gt;You can convert a string to number using the '+' symbol in Javascript.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Explained with examples here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fullstackdeveloper.guru/2021/04/30/how-do-numbers-differ-in-javascript-and-java/"&gt;https://fullstackdeveloper.guru/2021/04/30/how-do-numbers-differ-in-javascript-and-java/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>How to move a file or folder to trash in Java?</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Thu, 29 Apr 2021 17:01:57 +0000</pubDate>
      <link>https://dev.to/vijaysrj/how-to-move-a-file-or-folder-to-trash-in-java-16in</link>
      <guid>https://dev.to/vijaysrj/how-to-move-a-file-or-folder-to-trash-in-java-16in</guid>
      <description>&lt;p&gt;You can move a file or a folder to trash/ recycle bin in java using the below code:&lt;/p&gt;

&lt;p&gt;`Desktop.getDesktop().moveToTrash()'&lt;/p&gt;

&lt;p&gt;Here is a demo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fullstackdeveloper.guru/2021/04/29/how-to-move-a-file-folder-to-trash-recyclebin-in-java/"&gt;https://fullstackdeveloper.guru/2021/04/29/how-to-move-a-file-folder-to-trash-recyclebin-in-java/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>How to convert your Spring Boot app to serve over HTTPs instead of HTTP?</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Fri, 23 Apr 2021 12:19:30 +0000</pubDate>
      <link>https://dev.to/vijaysrj/how-to-convert-your-spring-boot-app-to-server-over-https-instead-of-http-2kff</link>
      <guid>https://dev.to/vijaysrj/how-to-convert-your-spring-boot-app-to-server-over-https-instead-of-http-2kff</guid>
      <description>&lt;p&gt;Converting your spring boot app to serve on HTTPS just requires few configuration to be added in application.yml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server:
  ssl:
    key-store: C:\softwares\jdk-16\bin\demokeystore
    key-store-password: demopass
    key-alias: demokey 
  port: 8443
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above configuration is enough. Here is the explanation behind it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fullstackdeveloper.guru/2021/04/23/how-to-convert-your-spring-boot-app-to-a-https-application/"&gt;https://fullstackdeveloper.guru/2021/04/23/how-to-convert-your-spring-boot-app-to-a-https-application/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>springboot</category>
    </item>
    <item>
      <title>How does HTTPs work?</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Thu, 22 Apr 2021 13:56:44 +0000</pubDate>
      <link>https://dev.to/vijaysrj/how-does-https-work-3dlf</link>
      <guid>https://dev.to/vijaysrj/how-does-https-work-3dlf</guid>
      <description>&lt;p&gt;Here is the basic algorithm of how HTTPS work:&lt;/p&gt;

&lt;p&gt;1.Browser hits website protected by HTTPS&lt;br&gt;
2.Server sends digital certificate&lt;br&gt;
3.Browser extracts public key from certificate&lt;br&gt;
4.Browser creates a session key&lt;br&gt;
5.Browser encrypts the session key using the public key and sends it to server&lt;br&gt;
6.Server decrypts session key using its private key&lt;br&gt;
7.Browser sends requests encrypted with the session key&lt;br&gt;
8.Server sends responses encrypted with the same session key&lt;/p&gt;

&lt;p&gt;A detailed explanation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fullstackdeveloper.guru/2021/04/22/how-does-https-work/"&gt;https://fullstackdeveloper.guru/2021/04/22/how-does-https-work/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>https</category>
    </item>
    <item>
      <title>The case of the binary logical operators '&amp;&amp;' and '||' in Javascript</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Wed, 21 Apr 2021 12:06:01 +0000</pubDate>
      <link>https://dev.to/vijaysrj/the-case-of-the-binary-logical-operators-and-in-javascript-312i</link>
      <guid>https://dev.to/vijaysrj/the-case-of-the-binary-logical-operators-and-in-javascript-312i</guid>
      <description>&lt;p&gt;In Javascript the binary logical operators '&amp;amp;&amp;amp;' and '||' behave differently compared to the same operators in a programming language like Java.&lt;br&gt;
This is because javascript binary logical operators can return even a number or a string, not just true or false!&lt;br&gt;
And again this is possible because Javascript has this concept of 'Truthy' and 'Falsy'.&lt;/p&gt;

&lt;p&gt;Anything of the below is considered as false by javascript:&lt;br&gt;
''&lt;br&gt;
false&lt;br&gt;
NaN&lt;br&gt;
null&lt;br&gt;
undefined&lt;/p&gt;

&lt;p&gt;Everything else is considered as true&lt;/p&gt;

&lt;p&gt;Here is a short post on how the above concept affects the binary logical operators in javascript:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fullstackdeveloper.guru/2021/04/21/how-the-binary-logical-operators-and-differs-in-javascript-from-java/"&gt;https://fullstackdeveloper.guru/2021/04/21/how-the-binary-logical-operators-and-differs-in-javascript-from-java/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>undefined vs null in Javascript</title>
      <dc:creator>Vijay SRJ</dc:creator>
      <pubDate>Tue, 20 Apr 2021 10:40:43 +0000</pubDate>
      <link>https://dev.to/vijaysrj/undefined-vs-null-in-javascript-36fg</link>
      <guid>https://dev.to/vijaysrj/undefined-vs-null-in-javascript-36fg</guid>
      <description>&lt;p&gt;If you are from the background of a programming language like Java , you might feel that the way to represent a “no value” is through the value “null”.&lt;/p&gt;

&lt;p&gt;But Javascript has two ways to denote a “no value”.&lt;/p&gt;

&lt;p&gt;One is “undefined”&lt;/p&gt;

&lt;p&gt;Another is “null”&lt;/p&gt;

&lt;p&gt;“undefined” represents “no value” whereas “null” represents “no object” to be more specific.&lt;/p&gt;

&lt;p&gt;Thus the major difference is that null is concerned with objects only.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When does Javascript return undefined?&lt;/strong&gt;&lt;br&gt;
When a variable is declared but not initialized , javascript throws undefined.&lt;/p&gt;

&lt;p&gt;Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var x;
console.log(x); // the value returned here is undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to invoke a property of an object which doesn’t exist , you get undefined:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var obj = {};
console.log(obj.name); // the value returned here is undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When does Javascript return null?&lt;/strong&gt;&lt;br&gt;
null means “missing”.&lt;/p&gt;

&lt;p&gt;So you get null whenever an object is missing.&lt;/p&gt;

&lt;p&gt;For example when you try to access a html element that does not exist , you get null.&lt;/p&gt;

&lt;p&gt;The below code returns null if there is no html element named “name” :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
console.log(document.getElementById("name"));
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to check if a function returns null or undefined?&lt;/strong&gt;&lt;br&gt;
Let’s say you are invoking a function in your javascript code and that function may return null or undefined. In that case you need to check for both null and undefined :&lt;br&gt;
&lt;/p&gt;

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

if(output === undefined || output === null){
        //logic here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can combine both the checks using ! operator like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(!output){
   //logic here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works because both undefined and null are treated as “false” by javascript.&lt;/p&gt;

&lt;p&gt;But you need to be cautious here , because if the output of the function in the above examples is an empty string , still the value of output is “false”.&lt;/p&gt;

&lt;p&gt;This is because javascript treats an empty string as false.&lt;/p&gt;

&lt;p&gt;Also the below are treated as false:&lt;/p&gt;

&lt;p&gt;0&lt;/p&gt;

&lt;p&gt;NaN&lt;/p&gt;

&lt;p&gt;false (the boolean value false itself)&lt;/p&gt;

&lt;p&gt;To summarize , javascript considers all these as false:&lt;/p&gt;

&lt;p&gt;false&lt;/p&gt;

&lt;p&gt;0&lt;/p&gt;

&lt;p&gt;”&lt;/p&gt;

&lt;p&gt;undefined&lt;/p&gt;

&lt;p&gt;null&lt;/p&gt;

&lt;p&gt;NaN&lt;/p&gt;

&lt;p&gt;Reposted from :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fullstackdeveloper.guru/2021/04/20/undefined-vs-null-in-javascript/"&gt;https://fullstackdeveloper.guru/2021/04/20/undefined-vs-null-in-javascript/&lt;/a&gt;&lt;/p&gt;

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