<?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: Jovan</title>
    <description>The latest articles on DEV Community by Jovan (@jovandj).</description>
    <link>https://dev.to/jovandj</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%2F248745%2F391de882-34a3-40e4-a2bc-4f6d39653fa2.jpg</url>
      <title>DEV Community: Jovan</title>
      <link>https://dev.to/jovandj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jovandj"/>
    <language>en</language>
    <item>
      <title>Learn AdonisJS pt. 1</title>
      <dc:creator>Jovan</dc:creator>
      <pubDate>Sat, 12 Nov 2022 18:47:26 +0000</pubDate>
      <link>https://dev.to/jovandj/learn-adonisjs-pt-1-1a04</link>
      <guid>https://dev.to/jovandj/learn-adonisjs-pt-1-1a04</guid>
      <description>&lt;p&gt;Just like many other Node.js backend developers, I spend most of my time building REST API's with &lt;a href="https://expressjs.com/"&gt;Express.js&lt;/a&gt;. It's a small, very easy to use HTTP library with a huge amount of middlewares and awesome, large community around it.&lt;/p&gt;

&lt;p&gt;But I didn't enjoy working with it. Something was missing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Express.js&lt;/code&gt; is just a small HTTP library. It accepts requests and returns responses. No matter how well it does it's job, applications I write are rarely just accepting requests and sending JSON responses.&lt;/p&gt;

&lt;p&gt;I would install npm packages that provide additional functionalities that I needed, but at what cost? Every new project, I had to install and configure a lot of third party packages, which took a lot of time and energy. These packages were small and independent, with the exception of &lt;code&gt;Express.js&lt;/code&gt; middlewares. It was very challenging to glue all of them together for days at end. It felt like building a Frankenstein's monster.&lt;/p&gt;

&lt;p&gt;I haven't started building my app, and I already lost a week and lost my mind.&lt;/p&gt;

&lt;p&gt;My needs have shifted from building minimal and fast apps, to building complete solutions from ground up in shortest amount of time possible. This also means that all the tools for the job would be readily available and easy to use.&lt;/p&gt;

&lt;p&gt;This is not a novel idea. Frameworks like Laravel, Ruby On Rails or Django have solved this problem 20 years ago. I was ready to start my new project with one of these, but one thing held me back: &lt;code&gt;Typescript&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I am not ready to give up on &lt;code&gt;Typescript&lt;/code&gt; type system, as I use it regulary and rely heavily on them. Being able to hover over an object and see exactly what methods and attributes it contains, or getting a compile time errors for silly mistakes is something I am not ready to let go.&lt;/p&gt;

&lt;p&gt;Having done some intense googling, a ray of hope shined upon me. A &lt;code&gt;Typescript&lt;/code&gt; first, battery included, developer first, ergonomy and productivity first &lt;code&gt;Typescript&lt;/code&gt; framework is discovered.&lt;/p&gt;

&lt;p&gt;Enter &lt;a href="https://adonisjs.com/"&gt;AdonisJS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;AdonisJS&lt;/code&gt; is a fully featured MVC web framework for &lt;code&gt;Node.js&lt;/code&gt;, built by &lt;a href="https://twitter.com/amanvirk1"&gt;Harminder Virk&lt;/a&gt;. It is a backend framework for building dynamic web applications using Typescript. Some of the things you can do with this framework are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle HTTP requestts&lt;/li&gt;
&lt;li&gt;Query the database&lt;/li&gt;
&lt;li&gt;Migrate and seed the database&lt;/li&gt;
&lt;li&gt;Authenticate users&lt;/li&gt;
&lt;li&gt;Upload files&lt;/li&gt;
&lt;li&gt;Send emails&lt;/li&gt;
&lt;li&gt;Validate requests&lt;/li&gt;
&lt;li&gt;Render HTML templates&lt;/li&gt;
&lt;li&gt;Test your apps&lt;/li&gt;
&lt;li&gt;Manage session and cookies&lt;/li&gt;
&lt;li&gt;Compile and serve frontend assets&lt;/li&gt;
&lt;li&gt;CORS, hashing, encryption&lt;/li&gt;
&lt;li&gt;Translate and internationalize&lt;/li&gt;
&lt;li&gt;Environment variables validation&lt;/li&gt;
&lt;li&gt;CLI tools&lt;/li&gt;
&lt;li&gt;VScode extension&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of this features are built in. AdonisJS team build and maintain all the first party modules that provide all these features, with great community modules coming up more and more.&lt;/p&gt;

&lt;p&gt;No more hunting for packages, no more cumbersone project setup and configuration. AdonisJS has it all. Finally, I can be productive from the day one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Project folder structure&lt;/li&gt;
&lt;li&gt;Eslint&lt;/li&gt;
&lt;li&gt;Prettier&lt;/li&gt;
&lt;li&gt;Typescript&lt;/li&gt;
&lt;li&gt;Webpack&lt;/li&gt;
&lt;li&gt;Live realoding&lt;/li&gt;
&lt;li&gt;.env&lt;/li&gt;
&lt;li&gt;Database migrations&lt;/li&gt;
&lt;li&gt;CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything else? Easy. Install package, run configuration command, I'm ready.&lt;/p&gt;

&lt;p&gt;Me being lazy is whole other topic.&lt;/p&gt;

&lt;p&gt;This is part one of learning AdonisJS series. Future posts will dig deeper in this framework so you can be productive and enjoy using it.&lt;/p&gt;

</description>
      <category>adonisjs</category>
      <category>node</category>
    </item>
    <item>
      <title>The internship story - Guidelines, resources and my experience</title>
      <dc:creator>Jovan</dc:creator>
      <pubDate>Thu, 28 Jul 2022 19:54:54 +0000</pubDate>
      <link>https://dev.to/jovandj/the-internship-story-guidelines-resources-and-my-experience-2ojh</link>
      <guid>https://dev.to/jovandj/the-internship-story-guidelines-resources-and-my-experience-2ojh</guid>
      <description>&lt;p&gt;In &lt;a href="https://dev.to/jovandj/the-first-internship-do-we-all-start-like-this-an"&gt;my previous post&lt;/a&gt;, I mentioned that I used free resources on the internet to learn and prepare myself for the internship interview. I want to elaborate more on that here, describe those resources and suggest a learning path that worked for me.&lt;/p&gt;

&lt;p&gt;The key takeaway of this post is that everything you need to know to land an internship or even a junior level job, is available on the internet. There is plenty of information, tutorials, videos, courses etc. for learning to build apps. You just have to find them, and start learning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Codecademy
&lt;/h2&gt;

&lt;p&gt;The very first line of code I've ever written was on &lt;a href="https://www.codecademy.com/"&gt;Codecademy&lt;/a&gt; in 2013. I stumbled upon it while googling and immediately started learning. At that point, I knew nothing. I haven't even heard of most of the stuff they teach there.&lt;/p&gt;

&lt;p&gt;The reason why I liked it is that they provided interactive environment for you to type your code. No need to set up anything on your own machine. Each lesson is self-contained, explained in detail. They provide exercises that you need to pass to continue forward. This cycle of learning and practicing small bits is valuable. Each lesson starts slow and easy and introduces new and harder concepts. It is very satisfactory to see yourself progressing through the course, one lesson at a time.&lt;/p&gt;

&lt;p&gt;But the crucial thing is that you have to write the code yourself. The only way to learn coding is to write a lot of code yourself. If you don't write it, you don't learn it. Muscle memory plays a huge role here. Once you do an exercise a couple of times, it transfers to muscle memory. Then it becomes easy because you don't have to think about it as much as before. It becomes automatic. No need to memorize anything by heart.&lt;/p&gt;

&lt;p&gt;For the learning path, do it in this order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will give you a strong foundation for building web sites and applications. If you choose to dive deeper into frontend, you can learn &lt;code&gt;React&lt;/code&gt;. It's a very popular &lt;code&gt;JavaScript&lt;/code&gt; library for building user interfaces. Lots of companies use it for day-to-day work.&lt;/p&gt;

&lt;p&gt;Then pick a language that will be your first real programming language. You will use this to build server side of your web app, or a desktop app. If you are more into web, &lt;code&gt;PHP&lt;/code&gt; is a great choice. &lt;code&gt;Python&lt;/code&gt; is beginner-friendly general purpose language. Very powerful, used in many areas of software engineering. In case you are more into mobile apps, learn &lt;code&gt;Java&lt;/code&gt; and &lt;code&gt;Kotlin&lt;/code&gt; to build &lt;code&gt;Android&lt;/code&gt; apps. For &lt;code&gt;IOS&lt;/code&gt;, &lt;code&gt;Objective-C&lt;/code&gt; and &lt;code&gt;Swift&lt;/code&gt; are the way to go.&lt;/p&gt;

&lt;p&gt;Some devs would suggest learning &lt;code&gt;C&lt;/code&gt; or &lt;code&gt;C++&lt;/code&gt; first, but I disagree. They are very old, low level languages which compile to machine code. These low level concepts would only confuse already overwhelmed students. You are already learning so much. Learning about pointers and memory management will only make your head explode. Unless you are into drivers and operating systems, then suit yourself.&lt;/p&gt;

&lt;p&gt;Learn &lt;code&gt;SQL&lt;/code&gt;. It's language that we use to communicate with the database. This is especially important because almost every app we build today uses a database. Otherwise, all the data we have would be gone every time we stop our apps. So we keep the data and use 1 to read it and manipulate. You will most of the time use it in conjunction with other languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  freeCodeCamp
&lt;/h2&gt;

&lt;p&gt;This is a kind of online code-school very similar to &lt;a href="https://www.codecademy.com/"&gt;Codecademy&lt;/a&gt;. Interactive code editor and bite-sized lessons are also present here. The curriculum is geared towards frontend development, although their newest content includes backend, databases, testing, security, job interview preparation and more.&lt;/p&gt;

&lt;p&gt;What &lt;a href="https://www.freecodecamp.org/"&gt;freeCodeCamp&lt;/a&gt; does better is that their curriculum is very practical and project oriented. You not only have to complete each exercise, but you will also have to do a project at the end of each course.&lt;/p&gt;

&lt;p&gt;This is very important, because what this does for you is basically prepare you for getting a job in web development. You not only learn the syntax of various programming languages, you also learn how to use them in practice. Syntax on it's own doesn't do much. Using it to create something of value is where the real learning takes place.&lt;/p&gt;

&lt;p&gt;There is no lesson that teaches you how to do these project. Instead, it requires you to spend some time to try and build them yourself. This teaches you another important skill: researching. Chances are, you won't be able to do the entire project on your own. And you don't have to. That's why you will use the internet to look for answers. Every problem you run into, so did a lot of people before you. For every question you might ask, someone else already did and got an answer. You just have to find it.&lt;/p&gt;

&lt;p&gt;Once you complete all projects in the course, you will get a certificate of completion. Don't be afraid to show it off. You spent a lot of time and effort to earn it and you should be proud of your progress.&lt;/p&gt;

&lt;p&gt;The curriculum is very well designed and you should do it in the order presented. This will take you from a beginner to a full stack developer. You will learn everything from building websites, web app, server side render apps, testing, databases etc. This is already more than enough skills for not only an internship, but an entry level job as well. A lot of people got their first jobs before even finishing the entire curriculum!&lt;/p&gt;

&lt;p&gt;Take you time, this will be a tough ride. It's going to take a lot of effort and time to finish the entire curriculum. I'm speaking about the timeframe of 6 to 12 months of daily learning. Be regular and consistent and you are good to go. You don't even have to finish the entire curriculum before starting to apply for jobs. Let alone internship. A lot of people haven't, including myself. The more finished projects you got under your belt, the more chances you stand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which one to choose
&lt;/h2&gt;

&lt;p&gt;Choose both. Do them both interchangeably. The reason for this is they have slightly different way of teaching. &lt;a href="https://www.codecademy.com/"&gt;Codecademy&lt;/a&gt; teaches languages more thoroughly, their syntaxes and concepts. On the other hand, &lt;a href="https://www.freecodecamp.org/"&gt;freeCodeCamp&lt;/a&gt; is more practical, letting you use the languages you know to build something practical.&lt;/p&gt;

&lt;p&gt;I wish you luck in your learning quests and internship hunt!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>The first internship, do we all start like this?</title>
      <dc:creator>Jovan</dc:creator>
      <pubDate>Mon, 11 Jul 2022 10:20:47 +0000</pubDate>
      <link>https://dev.to/jovandj/the-first-internship-do-we-all-start-like-this-an</link>
      <guid>https://dev.to/jovandj/the-first-internship-do-we-all-start-like-this-an</guid>
      <description>&lt;p&gt;Back in 2017 I was still in college. It was boring and I didn't learn much. I came to the conclusion that writing &lt;code&gt;PASCAL&lt;/code&gt; and &lt;code&gt;C&lt;/code&gt; on a piece of paper isn't going to do much for my future, so I decided to try my luck in the real world.&lt;/p&gt;

&lt;p&gt;I lived in a small city in a small country in South Eastern Europe. There was a total of 3 (three) mid-size companies in the entire city that employed all the programmers in the city. They also picked the best and brightest students from the collage for paid internships and possible full-time employment. Obviously, I wasn't one of them, so I took a different route.&lt;/p&gt;

&lt;p&gt;All of my free time from full-time studying I invested in learning programming online. I even purposely avoided studying for college so I could focus more time and effort for online learning. I believed that some subjects taught there were simply outdated and pointless, and to this day I have no idea what some of them were about, years after graduation.&lt;/p&gt;

&lt;p&gt;While I was looking for internship, I was learning anything I could find. Frontend, backend, JavaScript, Ruby, PHP, Java, you name it. It was obvious that I couldn't learn all of them at once (not good enough at least) and that I should narrow the scope. I opted for JavaScript, probably because I was more inclined towards frontend at that time, and I didn't know it could be used for backend yet.&lt;/p&gt;

&lt;p&gt;I literally wrote to every company in city asking for internship on their official Facebook page. And surprisingly, some of them were kind to answer. That alone made me feel so good, even though all but one were rejections.&lt;/p&gt;

&lt;p&gt;One of the companies offered me to pay them a visit, to meet and have an interview. This was a shocker for me, because I've never been in an IT company before. I didn't know how does it look inside, nor what kind of people are working there, not even what they do there at all. For me, being a shy and awkward kid (kid in spirit, biologically not so much) that was the scariest part of all.&lt;/p&gt;

&lt;p&gt;This was the comfort zone I needed to step out from.&lt;/p&gt;

&lt;p&gt;They sent an online assignment for me to do. It was a couple of algorithmic questions. I was never good with algorithms, so I did what I could. What I could not do, I did the best of my abilities, and wrote in comments what I didn't know, what stepping stones I had, and my reasoning for the solution I came up with, even though it was wrong. I believed that they are not looking for the solutions, they already knew better than I do, but instead, they wanted to see my thought process, logic and reasoning. So I wrote a lot of comments explaining what and why I did in the code.&lt;/p&gt;

&lt;p&gt;And it turned out I was right. I got some answers right, but not all of them. Regardless, I received the invitation for an interview.&lt;/p&gt;

&lt;p&gt;When I got there, HR lady welcomed me and led me to the empty office where we sat down and had a talk.&lt;/p&gt;

&lt;p&gt;It was a casual, friendly conversation. No stress. She was telling me about the company, and I was telling her about myself. Just like you would meet a new friend over a coffee.&lt;/p&gt;

&lt;p&gt;She didn't ask me anything tech related, only my interests, what I've been learning and what I wish to learn. I guess she was more interested to learn about my personality rather than knowledge.&lt;/p&gt;

&lt;p&gt;She asked me one technical question though, at the end of our conversation. The question was: "Can a constructor be private?" I knew what a constructor is, and what private methods are, but the combination of two never occurred to me before. It was food for thought. (Yes, constructors can be private)&lt;/p&gt;

&lt;p&gt;When she had no more questions, she left and two guys came: a senior frontend developer and a senior backend developer.&lt;/p&gt;

&lt;p&gt;It was my first time ever meeting real developers in person.&lt;/p&gt;

&lt;p&gt;They did ask me a lot of technical questions. Majority of questions were in the form of "what is x and what can you tell me about it", x being any technology they were using in their day to day work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Java&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;Angular&lt;/li&gt;
&lt;li&gt;HTML, CSS, SCSS&lt;/li&gt;
&lt;li&gt;WordPress&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There were also some technology specific questions, for example, what are primitive types in Java, and a trick question, what is a string in Java, for which I proudly answered it's an object, not a primitive type, having read about that just a few nights before.&lt;/p&gt;

&lt;p&gt;I knew the answers for the majority of questions, and all the answers I have learnt online for free. The only question I didn't know the answer for, to my memory, were design patterns. And I haven't learn them up until recently, years later in fact, unfortunately.&lt;/p&gt;

&lt;p&gt;The dev guys seem to be happy with my answers, so they left and the company director came in. He was the guy in charge for the entire office. He greeted me with a smile and sat in front of me. Just like with an HR lady, the talk was easy going and friendly. He asked me about my interests, what have I done, and what I would like to do in the future.&lt;/p&gt;

&lt;p&gt;I told him about my college studies, my self-teaching efforts, some of the simple apps I have build and that I want to learn as much as possible from the people who have more knowledge and experience than me.&lt;/p&gt;

&lt;p&gt;He really liked that answer, and especially he liked the fact that I reached out to them, not vise-versa. He then said that the company is already planning an internship programme for the students of the local university, and I came just before they planned to start scouting for interns. Therefore, he suggested that I should be the first student in this programme. Also on top on that, he asked me to invite some of my friends so we could make the first internship group and start right away.&lt;/p&gt;

&lt;p&gt;I did refer 2 of my friends to them, they went through the same screening process like I did, and they both passed. So we formed a group and officially become the first generation of interns in that company.&lt;/p&gt;

&lt;p&gt;On the first day, we got our own office, where we worked on an in-house project. We also each got a mentor, whom we could ask anything we didn't know. It is in that moment I realized my knowledge at the time was negligible. There was so much more to learn, I wouldn't even know that was the case if I never came here.&lt;/p&gt;

&lt;p&gt;That was the start of a whole new life for me. Life with constant learning, struggle balancing work and studies, ups and downs. It was worth it, because it was a great investment for a much better future.&lt;/p&gt;

&lt;p&gt;So if you are at a similar stage in your life and just starting out, I see you. As you can see, been there - done that. &lt;br&gt;
So if you have a question or two, I will be glad to help you. You can hit me up at &lt;a href="mailto:contact@jovandjukic.com"&gt;contact@jovandjukic.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>No, you do not have to use Mongodb with Node.js</title>
      <dc:creator>Jovan</dc:creator>
      <pubDate>Wed, 13 May 2020 09:00:00 +0000</pubDate>
      <link>https://dev.to/jovandj/no-you-do-not-have-to-use-mongodb-with-nodejs-2oeo</link>
      <guid>https://dev.to/jovandj/no-you-do-not-have-to-use-mongodb-with-nodejs-2oeo</guid>
      <description>&lt;p&gt;Vast majority of beginner nodejs tutorials use mongodb for the database. For simplicity sake, this is fine for beginners. It saves them the hassle of dealing with SQL table relations, so they can just stick any data in and get it out to render it on the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, you need to persist some data
&lt;/h2&gt;

&lt;p&gt;After learning the basics of building apps with Node.js, you may decide to build an app on your own. The courses and tutorials you learned from taught you Mongodb. It seems like next logical step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It has a nice Javascript API, just like Node.js&lt;/li&gt;
&lt;li&gt;It stores all data in JSON format&lt;/li&gt;
&lt;li&gt;You can easily fetch any data from the database&lt;/li&gt;
&lt;li&gt;You easily send that data to the client&lt;/li&gt;
&lt;li&gt;It's blazing fast, just like Node.js&lt;/li&gt;
&lt;li&gt;You don't have to learn another language just for databases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It seems like Mongodb is hand crafted for Javascript environment. For the first time ever, we can use one the same language in all 3 layers of our applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Javascript in the browser (User interface)&lt;/li&gt;
&lt;li&gt;Javascript on the server (Business logic)&lt;/li&gt;
&lt;li&gt;Javascript in the database (Data persistance)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Knowing this, its easy for beginners to fall into a trap of thinking Mongodb is the only database to use to persist data in Node.js apps. Experienced developers, coming to Node.js from other technical backgrounds, often ask: "Can I use Postgres/Mysql with Node.js?"&lt;/p&gt;

&lt;h2&gt;
  
  
  You can use any database you want
&lt;/h2&gt;

&lt;p&gt;Node.js is Javascript runtime environment. It is a symbiosis between a Javascript interpreter and some C++ code that let's you write server or desktop apps with Javascript language.&lt;/p&gt;

&lt;p&gt;This was not possible before, since Javascript is a language meant to be use in the context of a browser, thus confined within it for security reasons. Node.js sets Javascript free.&lt;/p&gt;

&lt;p&gt;Having Javascript execute outside of browsers allows us to do things such as networking, file system manipulation, getting operating system information, multi-threading (even though Javascript is a single-threaded language) and much more that was done with most other languages like Java, C#, PHP, Ruby, Python, etc.&lt;/p&gt;

&lt;p&gt;Since a Node.js app runs in the memory, a node app would need to preserve data in the database so it doesn't get lost. Which database can you use with node? Any database that you can find a driver for, which is all of them.&lt;/p&gt;

&lt;p&gt;There is nothing in Node.js that dictates your choice of database. It does not favor any particular database system, neither relational nor non-relational.&lt;/p&gt;

&lt;p&gt;Database is an external service from the point of view of a node app. You only need a driver and a running instance of a database to use it. Node.js doesn't care about that at all.&lt;/p&gt;

&lt;p&gt;Use whatever database you want.&lt;/p&gt;

</description>
      <category>node</category>
      <category>mongodb</category>
    </item>
    <item>
      <title>Difference between var, const and let</title>
      <dc:creator>Jovan</dc:creator>
      <pubDate>Wed, 06 May 2020 09:00:00 +0000</pubDate>
      <link>https://dev.to/jovandj/difference-between-var-const-and-let-h6f</link>
      <guid>https://dev.to/jovandj/difference-between-var-const-and-let-h6f</guid>
      <description>&lt;p&gt;There are 3 ways to declare a variable in Javascript: using one of the keywords &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Prior to ES6, &lt;code&gt;var&lt;/code&gt; used to be the only way to declare a variable. You had no other choice. However, it had some weird and unexpected behavior, which often resulted in hard to debug errors.&lt;/p&gt;

&lt;p&gt;Intuitively, you would think variable declared with &lt;code&gt;var&lt;/code&gt; is block scoped. Variable declared in, for example, &lt;code&gt;if&lt;/code&gt; statement, or a &lt;code&gt;for&lt;/code&gt; loop, is visible only in the scope of that statement or loop.&lt;/p&gt;

&lt;p&gt;Nope.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;It is &lt;strong&gt;function&lt;/strong&gt; scoped.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What this means is that a variable declared in a function would be visible in the entire function, even outside of &lt;code&gt;if&lt;/code&gt; blocks or loops. If declared outside of functions, it becomes global.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var test1 = 1; // Global, as expected

function testFunction() {
var test2 = 2; // Function scoped, as expected

if (true) {
var test3 = 3; // Still function scoped
console.log(test3); // Logs 3, still ok
}

console.log(test3); // Still logs 3 ???
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let and var
&lt;/h2&gt;

&lt;p&gt;Main difference between &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; is that &lt;code&gt;let&lt;/code&gt; is block scoped. Block scoping means that a variable is visible only in the block scope it is declared, block being any block of code surrounded by curly braces &lt;code&gt;{}&lt;/code&gt; such as a &lt;code&gt;for&lt;/code&gt; loop or &lt;code&gt;if&lt;/code&gt; statement, including any nested sub-blocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let test1 = 1; // Global, as expected

function testFunction() {
let test2 = 2; // Function scoped, as expected

if (true) {
let test3 = 3; // Still function scoped
console.log(test3); // Logs 3, still ok
}

console.log(test3); // Uncaught ReferenceError: test3 is not defined
}

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

&lt;/div&gt;



&lt;p&gt;Same example as previous one, this time all variables are declared with &lt;code&gt;let&lt;/code&gt; instead of &lt;code&gt;var&lt;/code&gt;. Now, if we use a variable declared with &lt;code&gt;let&lt;/code&gt; in an &lt;code&gt;if&lt;/code&gt; statement outside of it, we get a reference error.&lt;/p&gt;

&lt;p&gt;Inside of a block scope, &lt;code&gt;let&lt;/code&gt; is defined in it and all nested blocks, but not outside of it, while &lt;code&gt;var&lt;/code&gt; is defined in the entire function, regardless of blocks.&lt;/p&gt;

&lt;p&gt;Another main difference between &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; is that &lt;code&gt;var&lt;/code&gt; is initialized with &lt;code&gt;undefined&lt;/code&gt; by default. &lt;code&gt;Let&lt;/code&gt;, on the other hand, is not initialized at all until interpreter evaluates it. Accessing &lt;code&gt;var&lt;/code&gt; before its declaration will return &lt;code&gt;undefined&lt;/code&gt;, but &lt;code&gt;let&lt;/code&gt; would result in reference error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Const
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Const&lt;/code&gt; is very similar to &lt;code&gt;let&lt;/code&gt;, with some additional properties.&lt;/p&gt;

&lt;p&gt;Initializing &lt;code&gt;const&lt;/code&gt; is required, unlike &lt;code&gt;let&lt;/code&gt;. Declaring another &lt;code&gt;const&lt;/code&gt; with the same name is not possible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let foo; // ok
foo = "foo"; // ok

const bar; // SyntaxError: Missing initializer in const declaration
const bar = "bar"; // ok

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Const&lt;/code&gt; creates a read-only reference to the value. This does not mean a value cannot be changed, it means that you cannot re-assign to the same identifier again.&lt;/p&gt;

&lt;p&gt;Also, it does not mean the value becomes immutable. It still can be changed, but not by re-assigning. For example, you could change properties of an object, or remove from an array, but not by assigning new object or an array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Var&lt;/code&gt; is slowly becoming a thing of the past. Most browsers support &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; today, and are much easier to work with than &lt;code&gt;var&lt;/code&gt;. Some widely used libraries and old apps still use &lt;code&gt;var&lt;/code&gt;, so it is still widespread, but for new projects it is rarely used. It is much safer to use &lt;code&gt;const&lt;/code&gt; by default, only changing it to &lt;code&gt;let&lt;/code&gt; when re-assigning is necessary.&lt;/p&gt;

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