<?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: Sarvesh Kadam</title>
    <description>The latest articles on DEV Community by Sarvesh Kadam (@sarveshkadam).</description>
    <link>https://dev.to/sarveshkadam</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%2F474408%2Fe1aebab0-2a00-474a-ae1f-e77115519a19.jpg</url>
      <title>DEV Community: Sarvesh Kadam</title>
      <link>https://dev.to/sarveshkadam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarveshkadam"/>
    <language>en</language>
    <item>
      <title>How I Landed My First Developer Job In 8 Months</title>
      <dc:creator>Sarvesh Kadam</dc:creator>
      <pubDate>Thu, 03 Mar 2022 13:48:55 +0000</pubDate>
      <link>https://dev.to/sarveshkadam/how-i-landed-my-first-developer-job-in-8-months-4bkl</link>
      <guid>https://dev.to/sarveshkadam/how-i-landed-my-first-developer-job-in-8-months-4bkl</guid>
      <description>&lt;p&gt;If you’re looking for your first job or making a career change, you might feel intimidated by the sheer number of things that you have to face to get that gig. I’ve encountered similar challenges that resulted in rejections and, finally, low confidence. However, there are a few things that can help you overcome them.&lt;/p&gt;

&lt;p&gt;After multiple Interviews, Rejections and reading several “How to get the job” books. I landed my first developer job in 8 months.&lt;/p&gt;

&lt;p&gt;In this post, I have written down a small brain dump of the things that helped me and will help you to improve your application, raise your confidence and land your first developer Job.&lt;/p&gt;

&lt;p&gt;First the context&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I am currently working as a Software Developer&lt;/li&gt;
&lt;li&gt;Before that, I worked as a Quality Analyst, which was not a really exciting position for me.&lt;/li&gt;
&lt;li&gt;I began learning to code while working a full-time job and eventually landed my first development position.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Onto the good stuff&lt;/p&gt;

&lt;p&gt;The 4 things (mentioned below) helped me add credibility to my job application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Social Proof&lt;/li&gt;
&lt;li&gt;Resume&lt;/li&gt;
&lt;li&gt;Self Introductions&lt;/li&gt;
&lt;li&gt;Technical Questions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s go over them one by one&lt;/p&gt;

&lt;h3&gt;
  
  
  Social Proof
&lt;/h3&gt;

&lt;p&gt;By far the most effective technique to build credibility to your application is through social proof. Because it demonstrates to the recruiter your real interest and effort in the field.&lt;/p&gt;

&lt;p&gt;This can be accomplished in a variety of ways.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Portfolio&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is mostly regarded as a modern-day resume. Create a Portfolio site using either code or no-code tools; the choice is yours.&lt;/p&gt;

&lt;p&gt;You can have an about section where you mention a brief about your story, skillset, and your interests. A project section that includes at least three of your best projects or open-source contributions that demonstrate your technical skills.&lt;/p&gt;

&lt;p&gt;Write three blogs and list them in the blog area of your page. This demonstrates that you are genuinely interested in what you are doing.&lt;/p&gt;

&lt;p&gt;If you have any testimonials about your work, please include them.&lt;br&gt;
However, the project and blog sections can suffice.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;GitHub&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Github is a great way to add credibility to your application because it demonstrates your understanding of versioning systems, code maintainability, and so on.&lt;/p&gt;

&lt;p&gt;GitHub has a profile feature where you can create your profile by creating a repository with the name same as your username.&lt;/p&gt;

&lt;p&gt;You can get ideas from numerous GitHub profiles. Just google GitHub Profile Templates and you will get a list of them.&lt;br&gt;
Also pinned you best of the projects on the profile section.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;LinkedIn&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Linkedin is where your future employers are hanging out.&lt;/p&gt;

&lt;p&gt;So make sure you optimise your linked profile page, Fill out all necessary sections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Heading&lt;/strong&gt;- Please Do not include the phrase “Aspiring [_______] Developer” in the title. Mention the title you want to work on, Ex. Frontend Developer.&lt;br&gt;
You can even list down the main technologies in the title below&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Software Developer | React JS| Node JS&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;em&gt;About&lt;/em&gt; Section, provide information on yourself in bullet form, as well as information about the technology you worked with, some highlights of your project work, and other related interests in your industry.&lt;/p&gt;

&lt;p&gt;Include a link to your Github profile, portfolio, and top blogs in the &lt;em&gt;Featured&lt;/em&gt; Section. Then you can fill-up the &lt;em&gt;Education&lt;/em&gt; section, Also add &lt;em&gt;License and Certifications&lt;/em&gt; if you have any.&lt;/p&gt;

&lt;p&gt;Fill out the &lt;em&gt;Skill&lt;/em&gt; section and prioritise them.&lt;br&gt;
Finally complete out the &lt;em&gt;Projects&lt;/em&gt; section with the Title, Short Description and time you worked on it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resume
&lt;/h3&gt;

&lt;p&gt;Yes, Resumes are still relevant today. It will determine whether you receive the first nod and advance to the next round.&lt;/p&gt;

&lt;p&gt;Having said that, the purpose of a resume should be to get you an interview, not an offer.&lt;/p&gt;

&lt;p&gt;Keep the structure simple and save the file as a PDF with the filename &lt;em&gt;“Firstname_Lastname_resume”&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It should contain your name and contact information (Only email would be fine),&lt;/p&gt;

&lt;p&gt;Provide a brief description of yourself, followed by the Technologies and Languages section where you should list down the languages and framework you are proficient with. Do not provide a percentage or a rating to your level of knowledge in those areas.&lt;/p&gt;

&lt;p&gt;If this is your first job as a developer, the project section should be the most important part of your CV. &lt;br&gt;
It should include a brief explanation of the project, the technology used, and a link to the project. (If your project has a user interface, you can host it on Netlify or Vercel and provide a link, if not then you can provide the link to your GitHub repository and include an appropriate ReadMe file.)&lt;/p&gt;

&lt;p&gt;Then you can talk about your relevant work experience, followed by your interests and hobbies.&lt;/p&gt;

&lt;p&gt;Highly recommend checkout The Tech Resume Inside-Out by Gergely Orosz.&lt;/p&gt;

&lt;h3&gt;
  
  
  Self Introduction
&lt;/h3&gt;

&lt;p&gt;Self Introduction is very crucial; Making a positive impression will boost your chances of success.&lt;/p&gt;

&lt;p&gt;You have limited time, so keep it concise, to the point and appealing to the interviewer.&lt;/p&gt;

&lt;p&gt;Mention projects, work exp, which directly signifies how interested you are in this job. In the project section, specify the challenges you faced and how you solved them. Have ready with detail about the at least two challenges you faced while working, what solutions you implemented. This will set you out from the crowd.&lt;/p&gt;

&lt;p&gt;Refer to techinterviewhandbook.org&lt;/p&gt;

&lt;h3&gt;
  
  
  Technical Questions
&lt;/h3&gt;

&lt;p&gt;Preparing for technical questions will give you a lot more confidence when you go into the interviews.&lt;br&gt;
Write down the explanations for all of the concepts/questions that are frequently asked about your technology.&lt;/p&gt;

&lt;p&gt;For example, if you are applying for React Developer Position, list down details of concepts such as Elements, Fragments, Props, State, Prop drilling, etc. You get the gist.&lt;/p&gt;

&lt;p&gt;Google mostly asked questions related to the respective technology. Note down all of them.&lt;/p&gt;

&lt;p&gt;Revised them a day before the interview.&lt;/p&gt;

&lt;p&gt;Although other things are very important, such as algorithms and data structures. &lt;br&gt;
I would suggest going through the Basic Algorithms such as Reversing String, integer, array chunking, Anagram, etc and understanding Time and Space Complexity. These will give you a pretty good start to Data Structure and Algorithms.&lt;/p&gt;

&lt;p&gt;However, the four factors listed above will assist you in developing confidence to face interviews.&lt;/p&gt;

&lt;p&gt;The goal of this article was just to share what I learned during the process and hopefully, it will help you.&lt;/p&gt;

&lt;p&gt;I am writing more on my journey as a software developer on Twitter, you can &lt;strong&gt;&lt;a href="https://twitter.com/kadamsarvesh10"&gt;follow me there&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>career</category>
      <category>beginners</category>
      <category>programming</category>
      <category>job</category>
    </item>
    <item>
      <title>Getting started with NPM(Node Package Manager)</title>
      <dc:creator>Sarvesh Kadam</dc:creator>
      <pubDate>Fri, 30 Oct 2020 04:34:50 +0000</pubDate>
      <link>https://dev.to/sarveshkadam/getting-started-with-npm-node-package-manager-563</link>
      <guid>https://dev.to/sarveshkadam/getting-started-with-npm-node-package-manager-563</guid>
      <description>&lt;p&gt;In this article, we are going to discuss what is NPM (Node Package Manager) and how can we use it in our project.&lt;/p&gt;

&lt;p&gt;This is the third part of my &lt;a href="https://hashnode.com/series/node-modules-ckgn9w1n001uuo9s11k8e5cq2"&gt;Node Module series&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  NPM Overview:
&lt;/h4&gt;

&lt;p&gt;So what exactly is Node Package Manager?&lt;br&gt;&lt;br&gt;
The package is a piece of code that is managed by the Package Manager which is nothing but software that manages the installation and updating of packages.&lt;/p&gt;

&lt;p&gt;NPM as per the official &lt;a href="https://docs.npmjs.com/"&gt;document&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NPM is the world's largest software registry. Open-source developers from every continent use npm to share and borrow packages and many organizations use npm to manage private development as well.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, in NPM we use somebody else's open-source code managed by NPM by importing into our project.&lt;br&gt;&lt;br&gt;
NPM usually comes with Node JS when you download it.&lt;br&gt;
You can check if npm is installed on your machine by simply running the command &lt;code&gt;npm -v&lt;/code&gt; on your command-prompt.&lt;br&gt;
if it returns some version number, it means NPM is successfully installed.&lt;/p&gt;

&lt;p&gt;NPM has its registry at &lt;a href="https://docs.npmjs.com/"&gt;npmjs.com&lt;/a&gt; where we can discover packages that we can use.&lt;/p&gt;

&lt;p&gt;Let's look at one of the packages called &lt;a href="https://www.npmjs.com/package/chalk"&gt;chalk&lt;/a&gt; which is basically used for terminal styling.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4q5dVmOj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603909979665/T6w4cd8qR.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4q5dVmOj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603909979665/T6w4cd8qR.jpeg" alt="chalknpm2.jpg" width="566" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;pic credit npmjs.com &lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the above figure, we can see the weekly downloads of the package which suggests how popular is it.&lt;br&gt;&lt;br&gt;
Also, you can see this package dependencies in it. So this module which will serve as a dependency on our project is itself dependent on other modules.&lt;br&gt;
So this entire management process is taken care of by the Package Manager.&lt;br&gt;&lt;br&gt;
Even the source code is which is present on GitHub is given to us. We can navigate to it and verify if there are any open issues present.&lt;br&gt;&lt;br&gt;
One more thing before moving forward, the NPM packages come in different versions. The pattern which the version follows is semantic versioning.&lt;br&gt;&lt;br&gt;
As you can see, the latest version of the &lt;a href="https://www.npmjs.com/package/chalk"&gt;chalk&lt;/a&gt; module as and when I wrote is article is &lt;strong&gt;4.1.0&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It follows the semantic versioning as &lt;code&gt;Major_changes&lt;/code&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;code&gt;Minor_changes&lt;/code&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;code&gt;Patch&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Major_changes&lt;/code&gt; as the name stands, the significant changes made on the module which might affect your existing code.&lt;br&gt;&lt;br&gt;
&lt;code&gt;Minor_changes&lt;/code&gt; are a new enhancement or feature along with defect fixes been added which should not affect your existing code.&lt;br&gt;&lt;br&gt;
&lt;code&gt;Patch&lt;/code&gt; is the small bug fixes that will not crash your existing code.&lt;/p&gt;

&lt;p&gt;You learn more about semantic versioning on &lt;a href="https://semver.org/"&gt;semver.org&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  NPM Installation:
&lt;/h4&gt;

&lt;p&gt;Now to import any package from NPM, you first need to initialize NPM on your local project folder by running the command on the command prompt&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;


&lt;p&gt;Once you run the above command, it will ask you for some data as shown below such as package name, version, and so on.&lt;br&gt;
Much of this data can be kept as default as mention in the Round brackets &lt;strong&gt;()&lt;/strong&gt;.&lt;br&gt;
Also, the field such as &lt;code&gt;author&lt;/code&gt; and &lt;code&gt;license&lt;/code&gt; is for the folks who creating NPM packages.&lt;br&gt; On the other hand, we are just importing and using them to create our own application.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package name: (code_npm) code_npm
version: (1.0.0) 1.0.0
description: npm demo
entry point: (index.js) index.js
test command: test
git repository:
keywords: npm test
author: Sarvesh
license: (ISC)

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

&lt;/div&gt;


&lt;p&gt;Once you enter all the fields, it will create a JSON file with the values having the above properties and will ask you for confirmation as&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Is this OK? (yes) yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once you confirmed &lt;code&gt;yes&lt;/code&gt; it will create a &lt;code&gt;package.json&lt;/code&gt; file with all the data you entered as illustrated below.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "code_npm",
  "version": "1.0.0",
  "description": "npm demo",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1"
  },
  "keywords": [
    "npm",
    "test"
  ],
  "author": "Sarvesh",
  "license": "ISC"
}

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

&lt;/div&gt;


&lt;p&gt;Also, you can observe a &lt;code&gt;script&lt;/code&gt; Object having a &lt;code&gt;test&lt;/code&gt; property been added, which you can run using the &lt;code&gt;npm test&lt;/code&gt; command and it will give back the desired output as&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Error: no test specified"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now instead of doing this elongated method of initializing NPM and entering the custom properties values, you can simply run the command&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once you run this command, it will directly create a &lt;code&gt;package.json&lt;/code&gt; file with the default values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Fwbgc2E---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603968825440/3fcyAhRJG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Fwbgc2E---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603968825440/3fcyAhRJG.png" alt="pkgjson.PNG" width="318" height="73"&gt;&lt;/a&gt;&lt;br&gt;
Now to install the latest version of the &lt;strong&gt;chalk&lt;/strong&gt; package in your project you need to execute the command&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install chalk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can also install any specific version you need of chalk by just adding &lt;code&gt;@version number&lt;/code&gt; as shown below and also instead of &lt;code&gt;install&lt;/code&gt; you can simply put the short-hand &lt;code&gt;i&lt;/code&gt; flag which stands for installation&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i chalk@4.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will install two things, a &lt;code&gt;node_modules&lt;/code&gt; folder, and a &lt;code&gt;package-lock.json&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GV_3bM-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603968346848/EAws9k06a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GV_3bM-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603968346848/EAws9k06a.png" alt="folderdir.PNG" width="325" height="144"&gt;&lt;/a&gt;&lt;br&gt;
Also, it will add a new property called &lt;code&gt;dependencies&lt;/code&gt; to our &lt;code&gt;package.json&lt;/code&gt; file which contains the name of the package installed and its version.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
    "chalk": "^4.0.0"
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;node_module&lt;/code&gt; folder contains the packages folder and its dependencies folders. It gets modifies as and when the npm package gets installed.&lt;br&gt;&lt;br&gt;
The &lt;code&gt;package-lock.json&lt;/code&gt; contains the code which makes NPM faster and secure.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"chalk": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.0.0.tgz",
      "integrity": "sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==",
      "requires": {
        "ansi-styles": "^4.1.0",
        "supports-color": "^7.1.0"
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It mainly contains properties such as &lt;code&gt;version&lt;/code&gt; which is the semantic version number.&lt;br&gt;&lt;br&gt;
The &lt;code&gt;resolved&lt;/code&gt; property is the directory or location from which the package was fetched, here in this case it was fetched from &lt;a href="https://www.npmjs.com/package/chalk"&gt;chalk&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
The &lt;code&gt;integrity&lt;/code&gt; property is to assure, we get the same code if we install the dependency again.&lt;br&gt;&lt;br&gt;
The &lt;code&gt;requires&lt;/code&gt; object property represents the dependency of the &lt;code&gt;chalk&lt;/code&gt; package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;:- Do not make any changes or edit these two files &lt;code&gt;node_modules&lt;/code&gt; and &lt;code&gt;package-lock.json&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  NPM Usage:
&lt;/h4&gt;

&lt;p&gt;Now once we installed chalk to our project we can import it to our root project file using the &lt;code&gt;require()&lt;/code&gt; method and store that module in a variable &lt;code&gt;chalk&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Using the &lt;code&gt;red()&lt;/code&gt; method of the &lt;code&gt;chalk&lt;/code&gt; package, we have styled the "Hello World" text color in red. &lt;br&gt;
On running the command &lt;code&gt;node index.js&lt;/code&gt; we get the following output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UgSOILkv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603966334203/3ulfhvZnz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UgSOILkv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603966334203/3ulfhvZnz.png" alt="chalkop.png" width="426" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now there are many ways you can style your command line output using the chalk package, for more information refer to the &lt;a href="https://www.npmjs.com/package/chalk"&gt;Chalk official document&lt;/a&gt; on npm.&lt;/p&gt;

&lt;p&gt;Also, you can install the npm packages globally that is on our operating system rather than installing it in your local project by adding the &lt;code&gt;-g&lt;/code&gt; flag on the command line which stands for global as mentioned below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i nodemon -g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This global package will not affect our &lt;code&gt;package.json&lt;/code&gt; in any way since it is not installed locally.&lt;br&gt;
we have installed the &lt;code&gt;nodemon&lt;/code&gt; package globally which is used for automatic restarted of node application when file changes in the directory are observed.&lt;br&gt;
Refer to &lt;a href="https://www.npmjs.com/package/nodemon"&gt;nodemon&lt;/a&gt; for more information.&lt;/p&gt;

&lt;p&gt;We can use the nodemon package by running the application using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nodemon index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works similarly to &lt;code&gt;node index.js&lt;/code&gt;, except it keeps an eye on the file changes and it restarts the application once changes are detected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[nodemon] 2.0.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
Hello World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The &lt;code&gt;chalk&lt;/code&gt; styling will probably not work when you used &lt;code&gt;nodemon&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Finally, we will go through the &lt;code&gt;dev dependencies&lt;/code&gt;.There are some NPM packages or modules which won't be needed in our project production environment, but only for our development requirements.&lt;br&gt;
Such modules we install in our project using the &lt;code&gt;dev&lt;/code&gt; flag as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm i nodemon --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It creates new property in the &lt;code&gt;package.json&lt;/code&gt; called &lt;code&gt;devDependencies&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"devDependencies": {
    "nodemon": "^2.0.6"
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusion:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;NPM is a package manager that manages the 3rd Party Open source code which we can use in our project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Before using NPM modules, we need to initialize NPM locally using &lt;code&gt;npm init&lt;/code&gt; on your command line in the root of your project folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install any NPM package by using the command &lt;code&gt;npm i &amp;lt;package name&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can install the NPM package globally using the &lt;code&gt;-g&lt;/code&gt; flag&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also the package can be made development dependent using the &lt;code&gt;--save-dev&lt;/code&gt; flag&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you like this article do reach out to my &lt;a href="https://twitter.com/kadamsarvesh10"&gt;Twitter&lt;/a&gt; as I document my learning&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>javascript</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to use the NodeJS Core (Native) modules?</title>
      <dc:creator>Sarvesh Kadam</dc:creator>
      <pubDate>Sat, 24 Oct 2020 14:17:16 +0000</pubDate>
      <link>https://dev.to/sarveshkadam/how-to-use-the-nodejs-core-native-modules-4bpp</link>
      <guid>https://dev.to/sarveshkadam/how-to-use-the-nodejs-core-native-modules-4bpp</guid>
      <description>&lt;p&gt;In the last &lt;a href="https://sarveshkadam.tech/how-to-use-modular-patterns-in-nodejs"&gt;article&lt;/a&gt;, we discussed how to import our own files in NodeJS which included function, Objects, function constructor, and ES6 classes.&lt;br&gt;
You can find that article over &lt;a href="https://sarveshkadam.tech/how-to-use-modular-patterns-in-nodejs"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Today we are going to discuss how we can import and use Node Core(Native) modules into our own files.&lt;/p&gt;
&lt;h4&gt;
  
  
  Importing Node Core (Native) modules:
&lt;/h4&gt;

&lt;p&gt;Rather than creating our own custom modules every time, Node provides a set of modules to make our lives easier.&lt;/p&gt;

&lt;p&gt;We are going to discuss some of the modules, but you can find the entire list on the official node API document over &lt;a href="https://nodejs.org/dist/latest-v15.x/docs/api/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Importing Node modules is similar to that of importing your own modules we use the same &lt;code&gt;require()&lt;/code&gt; function to access it in our own file.&lt;/p&gt;

&lt;p&gt;But there are some modules which you may have used knowingly unknowingly which do not need to be imported. For eg. &lt;code&gt;console.log()&lt;/code&gt;, we have used the &lt;code&gt;console&lt;/code&gt; module many times without fetching it in our own local file as these methods are available &lt;strong&gt;globally&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let us look at one of the Core Native Modules which is &lt;strong&gt;File System&lt;/strong&gt; (&lt;code&gt;fs&lt;/code&gt;).&lt;br&gt;
There are n number of operations we can perform with the file system module such as reading a file, writing a file, and updating it to name a few.&lt;/p&gt;

&lt;p&gt;We are going to use the &lt;code&gt;fs&lt;/code&gt; module to read a file, even in that there are two ways we can perform this one by using the synchronous function &lt;code&gt;fs.readFileSync()&lt;/code&gt; and the other by asynchronous function &lt;code&gt;fs.readFile()&lt;/code&gt;, we'll discuss synchronous-asynchronous Node functions in future posts.&lt;/p&gt;

&lt;p&gt;Today, we'll use the asynchronous version i.e. &lt;code&gt;fs.readFile()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For this example, we have created two files one &lt;code&gt;main.js&lt;/code&gt; where we are going to perform file reading operation and &lt;code&gt;file.txt&lt;/code&gt; which is the file we are going to read.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xAsSIkvj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603442034534/DRk8tK6B8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xAsSIkvj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603442034534/DRk8tK6B8.png" alt="image.png" width="326" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The&lt;code&gt;file.txt&lt;/code&gt;contains some text in it.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, if we use the &lt;code&gt;fs&lt;/code&gt; module to read the file, without importing it as shown below&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;It will throw an error as &lt;code&gt;fs&lt;/code&gt; is not defined that is because the file system &lt;code&gt;fs&lt;/code&gt; module is not available globally as the &lt;code&gt;console&lt;/code&gt; module is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ReferenceError: fs is not defined
    at Object.&amp;lt;anonymous&amp;gt; (C:\Users\Sarvesh Kadam\Desktop\Training\blog\code snippets\Node Modular Pattern\main.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:1256:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1277:10)
    at Module.load (internal/modules/cjs/loader.js:1105:32)
    at Function.Module._load (internal/modules/cjs/loader.js:967:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Therefore, we need to import all the data from the file system module using the &lt;code&gt;require()&lt;/code&gt; function and store all that data in a variable &lt;code&gt;fs&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now you can name that variable anything, we named it &lt;code&gt;fs&lt;/code&gt; for readability and it's the standard which most developers follow.&lt;/p&gt;

&lt;p&gt;Using the &lt;code&gt;fs&lt;/code&gt; variable we can access the &lt;code&gt;readFile()&lt;/code&gt; method where we passed three arguments which are file path, character encoding &lt;code&gt;utf-8&lt;/code&gt;, and the callback function to give an output.&lt;/p&gt;

&lt;p&gt;You might ask why are we passing &lt;code&gt;utf-8&lt;/code&gt; as our argument in the &lt;code&gt;readFile()&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;The reason is, it encodes the value and gives the text as an output rather than giving a buffer as shown below&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 21&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The callback function, in turn, has two arguments an error (&lt;code&gt;err&lt;/code&gt;)and the actual content in the file (&lt;code&gt;data&lt;/code&gt;), and then we print that &lt;code&gt;data&lt;/code&gt; in the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Output:
Hello World!

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusion :
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Node has it's own set of Core (Native) Modules which we can use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Some of them are available globally, some of them need to be imported locally in your project/folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;require()&lt;/code&gt; function is used to fetch the particular module data and we stored all that data in a variable to access it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Thank you for your time for reading the article, please, give a follow on my &lt;a href="https://twitter.com/kadamsarvesh10"&gt;Twitter&lt;/a&gt; as I document my learning&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to use Modular patterns in NodeJS?
</title>
      <dc:creator>Sarvesh Kadam</dc:creator>
      <pubDate>Tue, 20 Oct 2020 04:32:52 +0000</pubDate>
      <link>https://dev.to/sarveshkadam/how-to-use-modular-patterns-in-nodejs-f97</link>
      <guid>https://dev.to/sarveshkadam/how-to-use-modular-patterns-in-nodejs-f97</guid>
      <description>&lt;p&gt;Modular Pattern is one of the fundamental features of Node.&lt;/p&gt;

&lt;p&gt;When building an application, as our application/code becomes complex we cannot put our entire code in one single file.&lt;/p&gt;

&lt;p&gt;As this becomes unmanageable, we use node modular pattern to write different files and export them(which includes functions, objects, and methods) to the main files.&lt;/p&gt;

&lt;p&gt;Now you might ask what exactly is a &lt;code&gt;module&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;In simple terms, a &lt;code&gt;module&lt;/code&gt; is nothing but a JavaScript file. That's It.&lt;/p&gt;

&lt;p&gt;With the node modular functionality, we can import your own external files, core node modules, and npm modules.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h4&gt;
  
  
  Importing your own files :
&lt;/h4&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article, we are going to discuss, how we can export and import our own files.&lt;br&gt;
Basically, there are two files &lt;code&gt;calculate.js&lt;/code&gt; from where we will export and import them into the &lt;code&gt;main.js&lt;/code&gt; file. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jzEzWA1g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603082860893/xGgR903x4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jzEzWA1g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603082860893/xGgR903x4.png" alt="mduleexport.png" width="350" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have both the files in the same folder for simplification purposes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--efXV89jc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603015526076/cwIgq_IuU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--efXV89jc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1603015526076/cwIgq_IuU.png" alt="image.png" width="321" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Importing a function:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//---- Exported file [calculate.js] ----
const add = (a,b)=&amp;gt;{
    return a + b
}

module.exports = add
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here we export a function called &lt;code&gt;add&lt;/code&gt; using &lt;code&gt;module.exports&lt;/code&gt;. Then this function gets imported to a different file using the &lt;code&gt;require&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;In node, each file is referred to as a &lt;code&gt;module&lt;/code&gt; and &lt;code&gt;exports&lt;/code&gt; is a property of the module Object.&lt;/p&gt;

&lt;p&gt;We can now invoke the function in the different files i.e &lt;code&gt;main.js&lt;/code&gt; by passing the arguments as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//------ Main File[main.js] ----

const add = require('./calculate') //name of the desired file
const result = add(2,4)
console.log(result); //Output : 6

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Importing an Object:&lt;/strong&gt; We can also export an entire object and access the different methods in it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//---- Exported file [calculate.js]  ----
const add = {
    result : (a,b)=&amp;gt;{
        return a + b
    }
}
module.exports = add

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

&lt;/div&gt;



&lt;p&gt;As we exported object add and imported to our main file using the &lt;code&gt;require&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;We can now access the &lt;code&gt;result&lt;/code&gt; method of the &lt;code&gt;add&lt;/code&gt; object using the &lt;code&gt;.&lt;/code&gt; dot operator&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//---- Main file[main.js] ----
const add = require('./calculate')

const result = add.result(5,8)

console.log(result) //Output : 13

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

&lt;/div&gt;



&lt;p&gt;Another way we can do the above Object exportations is by only exporting the method which you require rather than the entire object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//---- Exported file [calculate.js]  ----
const add = {
    result : (a,b)=&amp;gt;{
        return a + b
    }
}

module.exports = add.result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see we are importing the &lt;code&gt;result&lt;/code&gt; method in the &lt;code&gt;add&lt;/code&gt; Object, So this method can be directly invoked in the main file.&lt;/p&gt;

&lt;p&gt;This is good practice if you don't need the entire object but only require some methods/functions of it and also make our code more secure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//---- Main file[main.js] ----

const add = require('./calculate')
const result = add(5,8)
console.log(result) //Output : 13

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Importing a Function Constructor:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Function constructor is basically used to create a new instance of an Object which possesses the same properties as that of the main object/function.&lt;/p&gt;

&lt;p&gt;You can learn more about Function Constructor &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function#Constructor"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the below case, we create a new instance of the 'Add' Object using the &lt;code&gt;new&lt;/code&gt; keyword. This process where we create an instance of an object is called 'instantiation'.&lt;/p&gt;

&lt;p&gt;Then we export this instance using &lt;code&gt;module.exports&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//---- Exported file [calculate.js]  ----

function Add (){
    this.result = (a,b)=&amp;gt;{
        return a + b
    }
}

module.exports = new Add()

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

&lt;/div&gt;



&lt;p&gt;Now we can import it into our main file and access the 'result' method inside it, to get our calculated value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//---- Main file[main.js] ----

const add = require('./calculate2')
const result = add.result(1,3)
console.log(result); //Output : 4

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

&lt;/div&gt;



&lt;p&gt;This way we can export and import a function constructor.&lt;/p&gt;

&lt;p&gt;There is another way we can do this, which is by creating our new instance in the main file rather than in the exported file as shown above &lt;code&gt;module.exports = new Add()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We'll see that while exporting ES6 Classes which works similar to Function constructors.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Importing ES6 Classes:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;class&lt;/code&gt; is a special type of function where the &lt;code&gt;class&lt;/code&gt; keyword helps to initialize it and uses the &lt;code&gt;constructor&lt;/code&gt; method to store the properties. You can learn more ES6 classes &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we are going to export the entire &lt;code&gt;class&lt;/code&gt; using &lt;code&gt;module.exports&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//---- Exported file [calculate.js]  ----

const Add = class{
    constructor(a,b){
        this.a = a;
        this.b = b;
    }

    result(){
        return this.a + this.b
    }
}

module.exports = Add;

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

&lt;/div&gt;



&lt;p&gt;Now in our main file, we create a new instance using the &lt;code&gt;new&lt;/code&gt; keyword and access the &lt;code&gt;result&lt;/code&gt; method to get our calculated value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
//---- Main file[main.js] ----

const add = require('./calculate')

const result = new add(2,5)

console.log(result.result()); //Output : 7

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusion :
&lt;/h4&gt;

&lt;p&gt;In this article, we discussed how we can import our own files.&lt;/p&gt;

&lt;p&gt;We looked into a few ways how we can do this, such as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Importing Functions&lt;/li&gt;
&lt;li&gt;Importing an Object&lt;/li&gt;
&lt;li&gt;Importing a Function Constructor&lt;/li&gt;
&lt;li&gt;Importing ES6 Classes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are n number of ways in which you can export and import your own files.&lt;/p&gt;

&lt;p&gt;The other things which we did not discuss in this article are importing npm modules and importing node core modules which we'll look into in an upcoming article.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Thank you for your time for reading the article, please, give a follow on my &lt;a href="https://twitter.com/kadamsarvesh10"&gt;Twitter&lt;/a&gt; as I document my learning&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>codenewbie</category>
      <category>node</category>
      <category>javascript</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>How to get out of Tutorial Hell without getting out of it?</title>
      <dc:creator>Sarvesh Kadam</dc:creator>
      <pubDate>Fri, 09 Oct 2020 05:20:21 +0000</pubDate>
      <link>https://dev.to/sarveshkadam/how-to-get-out-of-tutorial-hell-without-getting-out-of-it-2cod</link>
      <guid>https://dev.to/sarveshkadam/how-to-get-out-of-tutorial-hell-without-getting-out-of-it-2cod</guid>
      <description>&lt;p&gt;&lt;strong&gt;Tutorial Hell&lt;/strong&gt; stated as per the &lt;a href="https://www.urbandictionary.com/define.php?term=Tutorial%20Hell"&gt;urban dictionary&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When you are learning Computer Science and programming but unfortunately you don't understand any of the code you wrote down from the tutorial but it works. Not only that you cannot write your own. It is very hard to get out of this and be able to write your own code. So it is a hell.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Do you agree with the above definition, or does your definition of Tutorial hell is different?&lt;/p&gt;

&lt;p&gt;If you ask me, I feel we do understand the code from the tutorial. &lt;br&gt;&lt;br&gt;It's just we are so reliant on the tutorial that we feel insecure if we are just given a blank code editor and told to write code or start with a new project.&lt;/p&gt;

&lt;p&gt;There is another situation that happens where we start with a tutorial we complete almost a 20 - 30 % of it.&lt;br&gt;&lt;br&gt; But at some point, we feel we are not on the same path as of the tutor or the complexity of a particular concept takes a drastic turn where we can't keep up with the pace of the course.&lt;/p&gt;

&lt;p&gt;Have you faced such obstacles in your learning?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TKQFLLk0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1602181088289/4nBSvbaKx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TKQFLLk0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1602181088289/4nBSvbaKx.jpeg" alt="kelly-sikkema-CbZC2KVnK8s-unsplash (2).jpg" width="500" height="333"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Pic credit &lt;a href="https://unsplash.com/"&gt;unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Here are a few ways you can modify your learning
&lt;/h3&gt;

&lt;p&gt;To overcome your problem on Imposter Syndrome or in simple terms not able to write code on your own. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I&lt;/strong&gt;f you have not yet picked any tutorial, do select a project-based tutorial, then divide the tutorial into many sections at your convenience.&lt;br&gt;&lt;br&gt;Now let say the tutorial is about building a Task App Project, then you should start building a To-Do App simultaneously with the tutorial.&lt;br&gt;&lt;br&gt;When a particular section is finished, stop the tutorial, go back to your own project folder and start building with the concepts you learned in that section. Do use Google as a primary resource and then refer to your own tutorial notes.&lt;/p&gt;

&lt;p&gt;In this way, you will gain some confidence in writing code on your own and you will feel much better while starting a new project without any step by step tutorial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;N&lt;/strong&gt;ow for the issue, when you get stuck in the tutorial and don't understand a particular topic the trainer is talking about.&lt;br&gt;&lt;br&gt; Stop the tutorial there itself and refer to other resources for that topic whether its a blog post, Official Documentation, or a short Youtube video.&lt;br&gt;&lt;br&gt;Once you understand that topic, return back to your main tutorial and you will have more clarity about what the tutor is explaining. &lt;/p&gt;

&lt;p&gt;In no way, I am an expert learner or have mastery over learning any concept. I myself started to learn code a few months back, Just want to lay down some methods which I used.&lt;/p&gt;

&lt;p&gt;On contrary, I would like to hear from you guys, any other methods which you used to overcome the roadblocks in your learning path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion :
&lt;/h3&gt;

&lt;p&gt;Now to conclude, start your own project simultaneously with the tutorial but add your own ideas and features to it, and if you get stuck somewhere in a tutorial, close that and refer to other resources for that particular topic which will give a much broader understanding of the topic.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Thank you for your time for reading the article, please, give a follow on my &lt;a href="https://twitter.com/kadamsarvesh10"&gt;twitter&lt;/a&gt; as I document my learning&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>100daysofcode</category>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to use Functions in JavaScript?</title>
      <dc:creator>Sarvesh Kadam</dc:creator>
      <pubDate>Wed, 07 Oct 2020 11:26:03 +0000</pubDate>
      <link>https://dev.to/sarveshkadam/how-to-use-functions-in-javascript-2mgm</link>
      <guid>https://dev.to/sarveshkadam/how-to-use-functions-in-javascript-2mgm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Functions&lt;/strong&gt; are the fundamental part of JavaScript programming language. It is a block of code that is reusable, i.e. the function can be called anywhere in the code and perform the required task as many times as you need it.&lt;/p&gt;

&lt;p&gt;In this article, we are gonna take look at various ways/methods of using JavaScript Function&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Function statement&lt;/strong&gt; :- 
In this method, we simply declared the function using the &lt;code&gt;function&lt;/code&gt; keyword along with the name of the function. We passed the arguments (if any) in the round&lt;code&gt;()&lt;/code&gt; bracket and the write the code what you want the function to perform when it is called or invoked inside parenthesis &lt;code&gt;{}&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the function statement, the function gets hoisted, that is you can access or invoke the function even before it is declared. You can learn more about hoisting where I have briefly discussed it in my &lt;a href="https://sarveshkadam.tech/learn-var-const-and-let-javascript-in-6-minutes"&gt;previous article&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;square(4) //Output: 16

function square(a){
    console.log(a * a);
}

square(2)

//Output : 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Function expressions&lt;/strong&gt; :- 
An anonymous function is created, which does not have its name and therefore we create an expression by assigning to a variable using the equal &lt;code&gt;=&lt;/code&gt; operator.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var square = function(a){
    console.log(a * a);
}

square(2)

//Output : 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;square&lt;/code&gt; variable is not the name of the function, it just points towards the address of the function in the memory space.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;:- In function expression, we cannot access the function before it is declared as it will return the variable &lt;code&gt;square&lt;/code&gt; as &lt;code&gt;undefined&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Immediately Invoked function expression&lt;/strong&gt;: -
In this, we simply declared an anonymous function as we discussed in the function expression above, but instead of assigning it to a variable, we wrapped it inside the parenthesis &lt;code&gt;()&lt;/code&gt; and we can immediately invoke or called the function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(function(a){
    console.log(a * a);
})(2)
//Output : 4

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

&lt;/div&gt;



&lt;p&gt;As you can see above example we create an anonymous function passed an argument &lt;code&gt;a&lt;/code&gt; and it returns the square of the argument, we can also invoke the function immediately after the curly brackets &lt;code&gt;{}&lt;/code&gt; as shown 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(a){
    console.log(a * a);
}(2))

//Output : 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Arrow Functions&lt;/strong&gt;:- Arrow functions are a concise and neat way to write JavaScript functions. It was introduced in ES6, in this way we don't need to explicitly mention the &lt;code&gt;function&lt;/code&gt; keyword while declaring the functions instead we use arrow &lt;code&gt;=&amp;gt;&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var square = (a)=&amp;gt;{
    console.log(a * a);
}
square(2)

//Output : 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since in the above code we are passing only one argument &lt;code&gt;a&lt;/code&gt; and returning only one value i.e. the square of the number we can make the code more concise by removing the argument brackets and parentheses &lt;code&gt;{}&lt;/code&gt; the curly braces&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var square = a =&amp;gt; console.log(a * a);
square(2)

//Output : 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before, moving forward let us discuss the about &lt;code&gt;this&lt;/code&gt; keyword, The &lt;code&gt;this&lt;/code&gt; in normal function points towards the Object where it is placed in, whereas in the arrow function it points toward the Global Object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = {
    square1 : ()=&amp;gt; {
        console.log(this);
    },
    square2 : function(){
        console.log(this);
    }
}

a.square1() //Output: Window {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}
a.square2() //Output: {square1: ƒ, square2: ƒ}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Callback function&lt;/strong&gt;:- A callback function is a function you passed as an argument to another function. Sounds Confusing!
Let's look at the below example.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var square = (callback)=&amp;gt;{
    callback(2);
}

square((a)=&amp;gt;{
    console.log(a * a); 
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in the above example, we create a square function where we pass the "callback" function as an argument, which itself has an argument which is declared as "2".&lt;br&gt;
During the invocation of the &lt;code&gt;square&lt;/code&gt; function, we pass the 'callback' function with the argument as &lt;code&gt;a&lt;/code&gt; and it prints the square of &lt;code&gt;a&lt;/code&gt; on the console.&lt;/p&gt;

&lt;p&gt;There is also another function called &lt;code&gt;async&lt;/code&gt; which we will discuss it in upcoming blogs since it also requires the concept of &lt;code&gt;promise&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;:- &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the function statement, we declared using the &lt;code&gt;function&lt;/code&gt; keyword and &lt;code&gt;this&lt;/code&gt; point towards the object it is located in.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In function expression, we assign the function to a variable using the &lt;code&gt;=&lt;/code&gt; equal operator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Immediately Invoked function expression is wrapped around the parenthesis &lt;code&gt;()&lt;/code&gt; and it is invoked immediately after the declaration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Arrow function which was introduced in ES6 is a concise way to write functions and the &lt;code&gt;this&lt;/code&gt; keyword inside arrow functions point towards Global Object irrespective of where it is located.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Callback functions are the functions that are passed as arguments in another function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Thank you for your time for reading the article, please, give a follow on my &lt;a href="https://twitter.com/kadamsarvesh10"&gt;twitter&lt;/a&gt; as I document my learning&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Getting started with JSON(JavaScript Object Notation)</title>
      <dc:creator>Sarvesh Kadam</dc:creator>
      <pubDate>Tue, 06 Oct 2020 04:44:52 +0000</pubDate>
      <link>https://dev.to/sarveshkadam/getting-started-with-json-javascript-object-notation-1g2f</link>
      <guid>https://dev.to/sarveshkadam/getting-started-with-json-javascript-object-notation-1g2f</guid>
      <description>&lt;p&gt;JSON(&lt;strong&gt;J&lt;/strong&gt;ava*&lt;em&gt;S&lt;/em&gt;&lt;em&gt;cript **O&lt;/em&gt;&lt;em&gt;bject **N&lt;/em&gt;*otation) is a storage format that is completely language independent and it is used to store and transport data. It's quite an important topic as the data which we fetch from external API usually consists of Arrays of elements which are in JSON format. &lt;/p&gt;

&lt;p&gt;The syntax of JSON is quite similar to the Object literal syntax which also consists of name, value pairs. But here both names, as well as values, are quoted in inverted commas.&lt;/p&gt;

&lt;p&gt;Let us 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;//Object literals syntax
let details = {
      firstName : "John",
      lastName : "Adams",
      age : 27
}

//JSON syntax
{
      "firstName" : "Mike",
      "lastName" :  "Bush",
      "age" : 25
}

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

&lt;/div&gt;



&lt;p&gt;It is believed that in previous years XML format was widely used which has tags surrounding the data.The above mention JSON data in XML format is represented as below&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;details&amp;gt;
     &amp;lt;firstName&amp;gt;Mike&amp;lt;/firstName&amp;gt;
     &amp;lt;lastName&amp;gt;Bush&amp;lt;/lastName&amp;gt;
     &amp;lt;age&amp;gt;25&amp;lt;/age&amp;gt;
&amp;lt;/details&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;As you can see the XML format is verbose as compare to JSON i.e. for a single value "Mike", the name "firstName" is repeated twice for the opening and closing tags which is quite unnecessary. Also, the JSON can be parsed to Object literal which makes it faster to work with.&lt;/p&gt;

&lt;p&gt;JSON is so popular that even JavaScript understands it and it has inbuilt functions to convert from JSON to object literal and vice versa.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Javascript provides &lt;code&gt;JSON.stringify()&lt;/code&gt; method to convert data from object literal format to JSON format
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const objectData = {
    firstName : "Mike",
    lastName : "Bush"
 }

 const JSONdata = JSON.stringify(objectData)
 console.log(JSONdata)

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Output&lt;/em&gt;:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"firstName":"Mike","lastName":"Bush"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
There is another method called&lt;code&gt;JSON.parse()&lt;/code&gt; which converts JSON format data to Object literal format
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const JSONdata = '{ "firstName" : "Mike", "lastName" : "Bush"}';
const ObjectData = JSON.parse(JSONdata)

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Output&lt;/em&gt;:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{firstName: "Mike", lastName: "Bush"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what I learned when I started with JSON. Understanding fundamentals and the methods of JSON are important as they are an elemental part of accessing information with API.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Conclusion *&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JSON syntax is similar to Object literal where both name-value pair is in inverted commas.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;JSON.stringify()&lt;/code&gt; Object --&amp;gt; JSON &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;JSON.parse()&lt;/code&gt; JSON --&amp;gt; Object &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Thank you for your time for reading the article, give a follow on my &lt;a href="https://twitter.com/kadamsarvesh10"&gt;twitter&lt;/a&gt; as I am documenting my learning&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Learn var, const, and let [JavaScript] in 6 minutes
</title>
      <dc:creator>Sarvesh Kadam</dc:creator>
      <pubDate>Sun, 04 Oct 2020 18:45:13 +0000</pubDate>
      <link>https://dev.to/sarveshkadam/learn-var-const-and-let-javascript-in-6-minutes-52g5</link>
      <guid>https://dev.to/sarveshkadam/learn-var-const-and-let-javascript-in-6-minutes-52g5</guid>
      <description>&lt;p&gt;If you have started learning JavaScript and even if you are in the early stages you must have come across &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt;, and &lt;code&gt;let&lt;/code&gt; variable declaration.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; were introduced in ES6 but before that only &lt;code&gt;var&lt;/code&gt; was the only way of variable declaration. Each one of them has its properties, scopes, and uses. &lt;/p&gt;

&lt;p&gt;Let us understand each one of them, the main differences between these ways of declaring variables&lt;/p&gt;

&lt;h3&gt;
  
  
  var :
&lt;/h3&gt;

&lt;p&gt;Variable declared with &lt;code&gt;var&lt;/code&gt; are &lt;strong&gt;mutable&lt;/strong&gt; i.e. they can be reassigned or even declare first and initialize in another step&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var num  //num declared -- &amp;gt; value of num is undefined 
num = 1  //num initialize/assigned-- &amp;gt; value of num is 1
num = 3 //num reassigned -- &amp;gt; value of num is 3

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;var&lt;/code&gt; is Global scoped and functional scoped.&lt;br&gt;
A variable has global scope when it is declared outside the function and that variable is accessible anywhere in the code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var firstName = "Sarvesh"
var lastName = "Kadam"
function greet(){
       console.log(firstName+" "+lastName)
}
greet() //*Output*: Sarvesh Kadam

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

&lt;/div&gt;



&lt;p&gt;Now the functional scoped says that if  a variable is declared with the &lt;code&gt;var&lt;/code&gt; keyword inside a function, it cannot be accessed outside it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hello(){
       var firstName = 'Sarvesh'
      }
console.log(firstName) //Will throw an error as firstName is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We cannot access the &lt;code&gt;firstName&lt;/code&gt; variable outside the function lexical scope. &lt;/p&gt;

&lt;h3&gt;
  
  
  const and let:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; are blocked scoped(we will this understand in a second). But first, let's look at the difference between them.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; is mutable (as seen in &lt;code&gt;var&lt;/code&gt;) whereas &lt;code&gt;const&lt;/code&gt; is immutable.&lt;/p&gt;

&lt;p&gt;As we can see in the below example, we can declare the variable at one instance and assigned a value to the "item" variable later or even reassign a new value to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let item //declaration
item = "food" //item is assigned a value -- &amp;gt; value of item is food
item = "clothes" //item variable declared -- &amp;gt; value of num is clothes

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

&lt;/div&gt;



&lt;p&gt;Let's look at &lt;code&gt;const&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const item ; //the value must be assigned while declaring
item = "food"  //error

const item2 = "pen"
item2 = "eraser" //error : value cannot be reassigned to constant variable

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

&lt;/div&gt;



&lt;p&gt;So in &lt;code&gt;const&lt;/code&gt;, we need to declare and initialize the variable at one instance only and we cannot reassign/change the value.&lt;/p&gt;

&lt;p&gt;Now both &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; are blocked scope i.e. we cannot access the variables outside parenthesis{} whether the block is a function or conditional statement&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 number1 = 2
    const number2 = 4
}
console.log(number1) //will throw an error as number1 is not defined
console.log(number2) //will throw an error as number2 is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the variables "number1" and "number2" are declared inside the if statement block we cannot access them, whereas in the case of &lt;code&gt;var&lt;/code&gt; we can access it as it is function scoped not block scoped.&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){
   var number = 5
}
console.log(number) //Output = 5

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

&lt;/div&gt;



&lt;p&gt;Now let us discuss a scenario where an object is declared with &lt;code&gt;const&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const player = {
    name : "Eden Hazard",
    team : "Read Madrid",
    position : "forward"
}

player.name = "Karim Benzema" //will re-assign the Value successfully

player = {
    name : "Modric",
    team : "Read Madrid",
    position : "forward"
}   //will throw an error 

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

&lt;/div&gt;



&lt;p&gt;As you can see in the above example we can change the properties of the object variable declared with &lt;code&gt;const&lt;/code&gt; but cannot reassign the entire object.&lt;/p&gt;

&lt;h4&gt;
  
  
  Some peculiar behavior :
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;var&lt;/code&gt; we can &lt;strong&gt;declare&lt;/strong&gt; a single variable multiple times and it will not throw an error. 
&lt;strong&gt;Note:&lt;/strong&gt; We don't use this property in any circumstances, just wanted to make you aware of it
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     var name = "sarvesh"
     console.log(name)  //Output: sarvesh
     var name = "rihan"
     console.log(name) //Output : rihan

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;let&lt;/code&gt; we can use the same name for declaring variables for different blocks and it will not affect the value of the global variables
&lt;/li&gt;
&lt;/ul&gt;

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

     console.log(a) //Output : 5 

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

&lt;/div&gt;



&lt;p&gt;As we have used a similar name "a" to declare and initialize the variable. Inside the block, the value of "a" is 8 and outside the block i.e. on the global object the value is 5.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;var&lt;/code&gt; the variable gets &lt;strong&gt;hoisted&lt;/strong&gt; i.e. (the &lt;code&gt;var&lt;/code&gt; variable is available even before any function/code is executed).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     console.log(name) //Output : undefined

     var name = "sarvesh"

     console.log(name) //Output : sarvesh

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

&lt;/div&gt;



&lt;p&gt;In the above code, the variable "name" is accessible even before its value is declared or initialize.&lt;br&gt;
As the JavaScript is parsed, before executing any function/code, the parser searches for any variable or function declarations and it sets a memory space for them with value as &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So here before execution, the variable "name" is stored in the memory space with the value of 'undefined' before any of the &lt;code&gt;log&lt;/code&gt; functions are executed.&lt;/p&gt;

&lt;p&gt;This entire phenomenon is called &lt;strong&gt;Hoisting&lt;/strong&gt; .( will explain in detail with another blog)&lt;/p&gt;

&lt;p&gt;This scenario will throw an error if we used &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; instead of &lt;code&gt;var&lt;/code&gt;, as these variables do not get hoisted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;var&lt;/code&gt; is functional scoped&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; are blocked scoped&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; are mutable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;const&lt;/code&gt; is immutable&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's a common practice to use &lt;code&gt;let&lt;/code&gt;,&lt;code&gt;const&lt;/code&gt; instead of &lt;code&gt;var&lt;/code&gt;, as the former two are blocked scope and not accessible outside the block,  as it makes the code more secured so if anybody changes the value outside the block it will bot affect the functionality of the entire code.&lt;/p&gt;

&lt;p&gt;Even in between &lt;code&gt;const&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt;, use &lt;code&gt;const&lt;/code&gt; wherever possible as it makes the code more readable as we understand if the value of the variable will be updated or not further down the code&lt;/p&gt;

&lt;p&gt;The above-mentioned points are good enough to get you started with &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt;.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Thank you for your time for reading the article, give a follow on my &lt;a href="https://twitter.com/kadamsarvesh10"&gt;twitter&lt;/a&gt; as I am documenting my learning&lt;/p&gt;


&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
