
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.0">Jekyll</generator><link href="https://iulia-codes.github.io/notes/feed.xml" rel="self" type="application/atom+xml" /><link href="https://iulia-codes.github.io/notes/" rel="alternate" type="text/html" /><updated>2022-01-02T10:43:25+00:00</updated><id>https://iulia-codes.github.io/notes/feed.xml</id><title type="html">Iulia’s Notes</title><subtitle>Programming is an universal activity!</subtitle><author><name>Iulia</name></author><entry><title type="html">Two Years in Homeoffice in a Nutshell</title><link href="https://iulia-codes.github.io/notes/life/work%20from%20home/two-years-of-homeoffice-in-a-nutshell/" rel="alternate" type="text/html" title="Two Years in Homeoffice in a Nutshell" /><published>2022-01-01T00:00:00+00:00</published><updated>2022-01-01T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/life/work%20from%20home/two-years-of-homeoffice-in-a-nutshell</id><content type="html" xml:base="https://iulia-codes.github.io/notes/life/work%20from%20home/two-years-of-homeoffice-in-a-nutshell/">&lt;p&gt;Sharing my experience from the years of homeoffice.&lt;/p&gt;
&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;It is 659 days from the start date to the end date, but not including the end date.&lt;/p&gt;

&lt;p&gt;Or 1 year, 9 months, 19 days excluding the end date.&lt;/p&gt;

&lt;p&gt;Or 21 months, 19 days excluding the end date.&lt;/p&gt;

&lt;p&gt;What do these numbers mean ? I will share the story below and as well what home office setup I have &lt;em&gt;that works&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id=&quot;a-warm-spring&quot;&gt;A warm spring&lt;/h2&gt;

&lt;p&gt;2020 started like any other year. The weather was getting warmer, the flowers were blooming and we just celebrated international woman’s day on the 8th of March. The work routine was following its normal course - drive to work, code, lunch, code and then go at the gym or home.&lt;/p&gt;

&lt;h2 id=&quot;last-day-at-the-gym&quot;&gt;Last day at the gym&lt;/h2&gt;

&lt;p&gt;Religously going to the gym as my habit dictates it, after work, at one of the gyms that our company provides for the employees. A benefit which I am very grateful for!&lt;/p&gt;

&lt;p&gt;In that specific day I was doing my running routine as usual. I started running in 2014 using the couch25k program (highly recommend!). The gym was empties than usual, but I did not think much of it, as it was usually empty at that time. However, the next day, everything changed.&lt;/p&gt;

&lt;h2 id=&quot;work-life-balance&quot;&gt;Work life balance&lt;/h2&gt;

&lt;p&gt;Working from home meant that the interactions with the colleagues were 100% virtual.&lt;/p&gt;
&lt;h2 id=&quot;homeoffice-where-possible&quot;&gt;Homeoffice where possible&lt;/h2&gt;

&lt;p&gt;Homeoffice was something I have experience with before. In that day of 13th of March 2020, the first day of homeoffice officially started. The world was just starting to experience the rage of the coronavirus, so to protect us, our company recommended us to work from home.&lt;/p&gt;

&lt;p&gt;My initial setup looked as below:&lt;/p&gt;

&lt;h2 id=&quot;the-homeoffice-journey&quot;&gt;The homeoffice journey&lt;/h2&gt;

&lt;p&gt;Our first day of homeoffice was the spring of 2020. Since then, my homeoffice setup needed to be adjusted. Therefore I adjusted the setup privately with:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;one monitor&lt;/li&gt;
  &lt;li&gt;one monitor holder, that you can adjust in height&lt;/li&gt;
  &lt;li&gt;one router&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the technical details of each:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;SAMSUNG LU28R554UQUEN 28 Zoll UHD 4K Monitor (4 ms Reaktionszeit, 60 Hz)&lt;/li&gt;
  &lt;li&gt;Invision 22-35 Zoll Monitor Halterung Höhenverstellbar, Neigung und Drehbar VESA 75/100 Gewicht 3-12 kg Gasunterstützter MX450&lt;/li&gt;
  &lt;li&gt;Fritzbox router&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;looking-into-the-future&quot;&gt;Looking into the future&lt;/h2&gt;

&lt;p&gt;Right now at the beginning of January 2022, there are is the so called “Homeofficepflicht”. This means, wherever possible, you should work from home.&lt;/p&gt;

&lt;p&gt;If you want to work from the office, there is a general 3G (genesen, geteset, geimpft) rule for the whole Germany.&lt;/p&gt;

&lt;h2 id=&quot;what-do-you-think-about-homeoffice&quot;&gt;What do you think about homeoffice?&lt;/h2&gt;

&lt;p&gt;What are your experiences with transitioning from in-office work to home-office work? Share your comments below! :)&lt;/p&gt;</content><author><name>Iulia</name></author><category term="life" /><category term="work from home" /><category term="homeoffice" /><category term="flex work" /><category term="work from home" /><category term="corona" /><category term="pandemic" /><category term="coronavirus" /><summary type="html">Sharing my experience from the years of homeoffice. Introduction</summary></entry><entry><title type="html">Top Seven Tips For Websummit</title><link href="https://iulia-codes.github.io/notes/websummit/conference/top-7-tips-for-websummit/" rel="alternate" type="text/html" title="Top Seven Tips For Websummit" /><published>2018-11-12T00:00:00+00:00</published><updated>2018-11-12T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/websummit/conference/top-7-tips-for-websummit</id><content type="html" xml:base="https://iulia-codes.github.io/notes/websummit/conference/top-7-tips-for-websummit/">&lt;p&gt;Websummit is the biggest tech conference in the world. This year I have attended websummit for the first time. With this post, I will share with the world tips &amp;amp; tricks, what I have learned and how you can get the most of websummit.&lt;/p&gt;

&lt;p&gt;First, what you need to know is that websummit  is more than a conference. It is a gathering where tech leaders, political &amp;amp; governmental people come together. Startups, angels and investors are also going to be on site.&lt;/p&gt;

&lt;h2 id=&quot;seven-tips-for-websummit&quot;&gt;Seven tips for websummit&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Prepare &amp;amp; Research early&lt;/p&gt;

    &lt;p&gt;You can pre-register for the yearly event as quick as from the last day of the current websummit.&lt;/p&gt;

    &lt;p&gt;Since the event is held yearly in late autumn, perhaps planning in January- February is a good idea.&lt;/p&gt;

    &lt;p&gt;I got my ticket in February 2018 for the year‘s summit.&lt;/p&gt;

    &lt;p&gt;With around 60.000 attendees, the event enables you to network with like-minded people.&lt;/p&gt;

    &lt;p&gt;Depending on the reason you are visiting, make a list of the companies you are interested in.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Participate at Partner workshops&lt;/p&gt;

    &lt;p&gt;You will find that most of the presentations are very high level. But going to the partner workshops is a very good idea to dwelve deeper into a specific topic ( and by this, I mean hands on code) aws from amazon had a pretty strong presence this year.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Participate at sunset summit / night summit&lt;/p&gt;

    &lt;p&gt;The sunset summit is a post-presentation event. It has a colorful vibe as it will give you a quick intro to Portugal. There you will be able to experience the taste, sound, culture of Portugal. You will get some free snacks like cheese or donuts, but prepare to invest from your own pocket.&lt;/p&gt;

    &lt;p&gt;Night summit is a similar ideea, with location within Lisbon.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Bring your own food and a bottle&lt;/p&gt;

    &lt;p&gt;I cannot stress this enough. There is street food at the event, but the long queues will wear you off. Also the prices are double if not triple with what you would pay in Lisbon.&lt;/p&gt;

    &lt;p&gt;This was quite disappointing to be honest.&lt;/p&gt;

    &lt;p&gt;Also, bring your own water bottle. Water is free and you will get a chance to refill the bottle to keep you hydrated and happy. Expect some deltaQ coffee as well, but the quality of the coffee could be improved in my ( and others ) opinion.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Wear your most comfortable shoes&lt;/p&gt;

    &lt;p&gt;This is no joke. You will have to sprint a lot through the pavilions. Make sure you wear the most comfy shoes you have, preferrably with a bigger sole. Only in the first day, I walked 14 km :)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Visit the booths&lt;/p&gt;

    &lt;p&gt;There are rarely any freebies at websummit. Knowledge is , however, for free. Make contact with the companies there if you are interested in a specific topic. They will want to scan your badge, and you will get a small gift for that. Sometimes there will be small games that you van play. Table tennis ( kicker) was pretty popular this year.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Network using the app&lt;/p&gt;

    &lt;p&gt;Websummit releases an app yearly. With this app you can find peers that share the same interest, company or location. Make a use of the app to create contacts.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope you have learned some new things. Have you participated at websummit before? Let me know your questions and I will answer them below.&lt;/p&gt;</content><author><name>Iulia</name></author><category term="websummit" /><category term="conference" /><category term="websummit" /><category term="conference" /><category term="venture" /><category term="startup" /><summary type="html">Websummit is the biggest tech conference in the world. This year I have attended websummit for the first time. With this post, I will share with the world tips &amp;amp; tricks, what I have learned and how you can get the most of websummit.</summary></entry><entry><title type="html">The best React and Redux resources for beginners</title><link href="https://iulia-codes.github.io/notes/react/redux/the-best-react-redux-resources-for-beginners/" rel="alternate" type="text/html" title="The best React and Redux resources for beginners" /><published>2017-11-12T00:00:00+00:00</published><updated>2017-11-12T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/react/redux/the-best-react-redux-resources-for-beginners</id><content type="html" xml:base="https://iulia-codes.github.io/notes/react/redux/the-best-react-redux-resources-for-beginners/">&lt;p&gt;This page summarizes my research made to do a fast ramp-up in the topics of React/Redux. These both frameworks are like bread and butter for eachother and go well hand in hand. You can start by learning either of them - but it is always assumed that you have a Javascript background.&lt;/p&gt;

&lt;h2 id=&quot;react-resources&quot;&gt;React resources&lt;/h2&gt;
&lt;p&gt;⋅⋅* &lt;a href=&quot;https://courses.thinkful.com/react-001v3&quot;&gt;Thinkful React&lt;/a&gt;
I always liked the way the Thinkful courses are written. Light reading and easy to understand formulations.&lt;/p&gt;

&lt;p&gt;⋅⋅*  &lt;a href=&quot;https://reactforbeginners.com/&quot;&gt;React for Beginners&lt;/a&gt;
Wes Bros offers a React for Beginners course that will guide you through the basics of React, while building an app.&lt;/p&gt;

&lt;h2 id=&quot;redux-resources&quot;&gt;Redux resources&lt;/h2&gt;

&lt;p&gt;⋅⋅* &lt;a href=&quot;https://egghead.io/courses/getting-started-with-redux&quot;&gt;Redux Egghead&lt;/a&gt;
There is no more obvious first place to go for Redux resources, than the Egghead series made by the creator. Completing this series will give you a good start, but also raise questions that you will be able to answer later, in practice.&lt;/p&gt;

&lt;h2 id=&quot;react--redux&quot;&gt;React + Redux&lt;/h2&gt;
&lt;p&gt;⋅⋅* &lt;a href=&quot;https://mva.microsoft.com/en-US/training-courses/using-react-with-redux-17730&quot;&gt;Using React with Redux by Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Microsoft Virtual Academy always offers extremly easy to follow resources. I really like this resource that combines the understanding of both React and Redux.&lt;/p&gt;

&lt;iframe src=&quot;https://mva.microsoft.com/en-US/training-courses-embed/using-react-with-redux-17730/Video-Using-React-with-Redux-8VEwsDb2D_411787177&quot; width=&quot;636&quot; height=&quot;480&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;</content><author><name>Iulia</name></author><category term="react" /><category term="redux" /><category term="beginner" /><category term="react" /><category term="redux" /><summary type="html">This page summarizes my research made to do a fast ramp-up in the topics of React/Redux. These both frameworks are like bread and butter for eachother and go well hand in hand. You can start by learning either of them - but it is always assumed that you have a Javascript background.</summary></entry><entry><title type="html">How To Show Word Frequency From Your Whatsapp Conversations</title><link href="https://iulia-codes.github.io/notes/how-to-show-word-frequency-from-your-whatsapp-conversations/" rel="alternate" type="text/html" title="How To Show Word Frequency From Your Whatsapp Conversations" /><published>2017-08-03T00:00:00+00:00</published><updated>2017-08-03T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/how-to-show-word-frequency-from-your-whatsapp-conversations</id><content type="html" xml:base="https://iulia-codes.github.io/notes/how-to-show-word-frequency-from-your-whatsapp-conversations/">&lt;p&gt;Data science is beautiful. It is so beautiful that it offers you the possibility to understand what you actually feel. In this article,
I will show you how to export your whatsapp conversation and make something meaningful of it. At the end, we will have a word cloud created.&lt;/p&gt;

&lt;p&gt;Step1: Export your WhatsApp conversation&lt;/p&gt;

&lt;p&gt;To export your WhatsApp conversation, choose your wished chat. Click on “More” and choose “Export”. You can either e-mail it to yourself or
save it to a Google Drive.&lt;/p&gt;

&lt;p&gt;Step2: Data cleanup&lt;/p&gt;

&lt;p&gt;This step is the largest one, as it requires us to clean the data that we want to analyze. For this step you need Sublime Text and Excel.&lt;/p&gt;

&lt;p&gt;Open your WhatsApp text file in Sublime text. Every conversation has a pattern with time+name. To remove time+name simply do a REGEX search 
by using Sublime.&lt;/p&gt;

&lt;p&gt;Numbers are not important so:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;start by removing the numbers from the conversation, as shown here: &lt;a href=&quot;https://forum.sublimetext.com/t/deleting-digits-after-a-specific-character/14620/2&quot; target=&quot;_blank&quot;&gt; Remove timestamp and name &lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What the above does, is simply to remove every number it finds inside the conversation. Great, now you have removed numbers … there 
are some other things to do:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;remove other special characters like “:” by selecting the characters and replacing it with blank&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By now, you should have a cleaned up file that contains only the conversation.&lt;/p&gt;

&lt;p&gt;Step3: Analyze words&lt;/p&gt;

&lt;p&gt;Clone this repository and run it locally. &lt;a href=&quot;https://github.com/DaleSeo/word-frequency&quot; target=&quot;_blank&quot;&gt; Github repository &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is one more step in able to run the program: a word must be on each line. &lt;a href=&quot;https://forum.sublimetext.com/t/split-into-lines/10196&quot; target=&quot;_blank&quot;&gt; Split text into lines &lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Highlight your space, press Alt+F3 (windows) to select all, hit return.&lt;/li&gt;
  &lt;li&gt;If the whitespace varies, use a regex search, then select all as above and hit return.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, analyze the words by running:&lt;/p&gt;

&lt;p&gt;node analyze input.txt out.txt&lt;/p&gt;

&lt;p&gt;The file generated will be like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; Easy occurred 1 times
  Nb occurred 43 times
  Omg occurred 4 times
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Step4: Cleanup occurence results&lt;/p&gt;

&lt;p&gt;Once you have a file as in the sample shown above, the next step is to import it into Excel.&lt;/p&gt;

&lt;p&gt;Open Excel and go to &lt;b&gt;Data &amp;gt; From Text&lt;/b&gt;, Delimited &amp;gt; Spaces.&lt;/p&gt;

&lt;p&gt;Cleanup and filter the occurence results. Remove column occurence and filter the columns by word count… The result should look like this:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ca	303
in	260
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Step5: Visualize your data&lt;/p&gt;

&lt;p&gt;A few words and their occurences would not give us a lot of information. Therefore, let’s use two tools to visualize your data:&lt;/p&gt;

&lt;p&gt;1) Semantic Word Cloud Vizualization&lt;/p&gt;

&lt;p&gt;http://wordcloud.cs.arizona.edu/&lt;/p&gt;

&lt;p&gt;Paste the words and you will have a nicely presented cloud of words. This is nice because it is an academical tool looking at the
importance of words.&lt;/p&gt;

&lt;p&gt;2) Word clouds&lt;/p&gt;

&lt;p&gt;http://www.wordclouds.com/&lt;/p&gt;

&lt;p&gt;Paste the words and their frequency and you will be presented with a word cloud.&lt;/p&gt;</content><author><name>Iulia</name></author><summary type="html">Data science is beautiful. It is so beautiful that it offers you the possibility to understand what you actually feel. In this article, I will show you how to export your whatsapp conversation and make something meaningful of it. At the end, we will have a word cloud created.</summary></entry><entry><title type="html">Most Common Git Commands</title><link href="https://iulia-codes.github.io/notes/most-common-git-commands/" rel="alternate" type="text/html" title="Most Common Git Commands" /><published>2017-05-19T00:00:00+00:00</published><updated>2017-05-19T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/most-common-git-commands</id><content type="html" xml:base="https://iulia-codes.github.io/notes/most-common-git-commands/">&lt;p&gt;Clone a repository:&lt;/p&gt;

&lt;p&gt;git clone repo_name&lt;/p&gt;

&lt;p&gt;Show all branches of a repository:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;show all remote and local branches
git branch -a&lt;/li&gt;
  &lt;li&gt;show all local branches
git branch -r&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create a new branch:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;git checkout -b new_branch_name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Checkout a specific branch (where branch_name is the name of the branch you want to checkout):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;git fetch –all&lt;/li&gt;
  &lt;li&gt;git checkout branch_name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ignore files without adding them to .gitignore&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;edit .gitconfig&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;[alias]
  ignore = update-index –assume-unchanged
  unignore = update-index –no-assume-unchanged&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;add the desired file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;git ignore myFile.extension&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;remove the file from being ignored&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;git uningnore myFile.extension&lt;/p&gt;

&lt;p&gt;Amend the previous commit:&lt;/p&gt;

&lt;p&gt;git commit –amend&lt;/p&gt;

&lt;p&gt;Create a patch from the last commit:&lt;/p&gt;

&lt;p&gt;git format-patch -1 HEAD  –stdout &amp;gt; 0001-last-commits.patch&lt;/p&gt;

&lt;p&gt;Create a patch from the last commit (another variant that prints the file name as the commit name):&lt;/p&gt;

&lt;p&gt;git format-patch -1 &lt;SHA1-ID&gt;&lt;/SHA1-ID&gt;&lt;/p&gt;

&lt;p&gt;Apply a patch from the last patch file:&lt;/p&gt;

&lt;p&gt;patch -p1 &amp;lt; example.patch&lt;/p&gt;</content><author><name>Iulia</name></author><summary type="html">Clone a repository:</summary></entry><entry><title type="html">Closure for dummies - a complete guide to understanding closures in Javascript</title><link href="https://iulia-codes.github.io/notes/guides/closures-for-dummies/" rel="alternate" type="text/html" title="Closure for dummies - a complete guide to understanding closures in Javascript" /><published>2017-01-25T00:00:00+00:00</published><updated>2017-01-25T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/guides/closures-for-dummies</id><content type="html" xml:base="https://iulia-codes.github.io/notes/guides/closures-for-dummies/">&lt;p&gt;The concept of closures in Javascript can be hard to grasp at first. However, once you will have that &lt;b&gt;a-ha&lt;/b&gt; moment, a new powerful capability of Javascript will have been revealed to you. That’s ok, because closures are considered an advanced concept of Javascript.&lt;/p&gt;

&lt;p&gt;According to &lt;b&gt;Javascript - the definitive guide, 6th edition&lt;/b&gt; a function is a block of JavaScript code that is defined once but may be executed, or invoked, any number of times.&lt;/p&gt;

&lt;p&gt;In JavaScript, functions are objects and can be assigned to variables. JavaScript function definitions can be nested within other function, &lt;b&gt;and they have access to any variables that are in the scope where they are defined&lt;/b&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Learn closures with  Bob Tabor and cats&lt;/li&gt;
&lt;/ul&gt;

&lt;iframe src=&quot;https://channel9.msdn.com/Series/Javascript-Fundamentals-Development-for-Absolute-Beginners/Fundamentals-of-JavaScript-Closures-20/player&quot; width=&quot;960&quot; height=&quot;540&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;Bob defines a closure as &lt;i&gt;a special type of object, that combines a function and the environment in which that function was created.&lt;/i&gt; The environment consists of the local variables that were in scope at the time the closure was created , as well as any input parameters that were passed in. We get both the function implementation, as well as its environment.&lt;/p&gt;

&lt;p&gt;You are binding some data to a function, storing it as a variable for later usage in the program.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Learn closures with a definitive example&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Javascript uses &lt;i&gt;lexical scoping&lt;/i&gt; - functions are executed using the variable scope that was in effect when they were &lt;b&gt;defined&lt;/b&gt; not the variable scope that is in effect when they are invoked.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Definition 1: Closure&lt;/b&gt;  The combination of a function object and a scope (a set of variable bindings) in which the function’s variables are resolved, is called a &lt;b&gt;closure&lt;/b&gt; in computer science literature.&lt;/p&gt;

&lt;p&gt;Every Javascript function is a closure: they are objects and they have a scope chain associated with them. Let us look at an example&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Create two counters&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// =&amp;gt; 0&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// =&amp;gt; 0: they count independently&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// reset() and count() methods share state&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// =&amp;gt; 0: because we reset c&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// =&amp;gt; 1: d was not reset&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The counter() function returns a “counter” object. The object has two methods:&lt;br /&gt;
    *    count() - returns the next integer
    *    reset() - resets the internal state&lt;/p&gt;

&lt;p&gt;The two methods share the acces to the private variable b.
Each invocation of counter() creates a new scope chain and a new private variable&lt;/p&gt;

&lt;p&gt;So if you call counter() twice, two counter objects with different private variables will result.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Master the JavaScript interview : What is a closure?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article from  &lt;a href=&quot;https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-closure-b2f0d2152b36#.s8tp5gf5h&quot; target=&quot;_blank&quot;&gt;Medium&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Definition 2: (Closures)&lt;/b&gt;A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.&lt;/p&gt;

&lt;p&gt;You see, the definition is simply another flavor of what we know so far.&lt;/p&gt;

&lt;p&gt;In a next example, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.get()&lt;/code&gt; method is defined inside the scope of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getSecret()&lt;/code&gt;, which gives it access to any variables from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getSecret()&lt;/code&gt;, and makes it a privileged method. In this case, the parameter, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;secret&lt;/code&gt;. Have a play with closure on JSBin:&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;https://jsbin.com/gareno/4/embed?html,js,output&quot;&gt;JS Bin on jsbin.com&lt;/a&gt;&lt;script src=&quot;https://static.jsbin.com/js/embed.min.js?3.40.3&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Learn closures with Joe&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your skill as a JavaScript developer can be measured by how well you understand closures. &lt;a href=&quot;https://code.tutsplus.com/tutorials/closures-in-javascript--cms-24009&quot; target=&quot;_blank&quot;&gt;Joe says so&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Definition 3: (Closures)&lt;/b&gt; The idea of closures is accessing variables from outside of the current local scope. From any function you can access the variable that are above the function in the scope hierarchy.&lt;/p&gt;

&lt;p&gt;The idea becomes more useful when we have a function inside another function. Let us see an example below. From the inside() function we can access the firstScope variable from the outside function (because they are functions inside a function).&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outside&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;firstScope&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inside&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;secondScope&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;firstScope&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;secondScope&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;inside&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The result will be: onetwo.&lt;/p&gt;

&lt;p&gt;The real benefit comes into play when we actually return the function:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outside&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;firstScope&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inside&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;secondScope&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;two&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;firstScope&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;secondScope&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inner&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;outside&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;inner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The result will  be the same: onetwo. The function returned a value that referenced something from outside the scope.&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/1lczrpwwZIE&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;ul&gt;
  &lt;li&gt;Scope and closure with Udacity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I like Udacity’s take on closures. &lt;a href=&quot;https://classroom.udacity.com/courses/ud015/lessons/2593668697/concepts/25411890500923&quot; target=&quot;_blank&quot;&gt;https://classroom.udacity.com/courses/ud015/lessons/2593668697/concepts/25411890500923&lt;/a&gt; No comments needed, just watch for yourself.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Pluralsight take on closures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The top of the cake is maybe this take of Pluralsight &lt;a href=&quot;https://app.pluralsight.com/player?course=advanced-javascript&amp;amp;author=kyle-simpson&amp;amp;name=advanced-javascript-m3&amp;amp;clip=0&quot; target=&quot;_blank&quot;&gt;https://app.pluralsight.com/player?course=advanced-javascript&amp;amp;author=kyle-simpson&amp;amp;name=advanced-javascript-m3&amp;amp;clip=0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Definition 4: (Closures)&lt;/b&gt; Closure is the capability for a function to remember and access its lexical scope even when the function is executing outside that lexical scope.&lt;/p&gt;

&lt;p&gt;Javascript has first class functions: functions can be passed around and executed in different environments.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;firstScope&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inside&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;firstScope&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;bam&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;baz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bam&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;baz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;baz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//&quot;bar&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

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

&lt;p&gt;We call function bam. There is a bubble around 1-9 and function can access the variable on line 12. The lexical scope stayed attached to that function, no matter where it was transported.&lt;/p&gt;

&lt;h2&gt;What practical example have you used to understand closures? Share it here!&lt;/h2&gt;

&lt;hr /&gt;</content><author><name>Iulia</name></author><category term="guides" /><category term="closure" /><category term="function" /><category term="javascript" /><category term="object" /><category term="demo" /><summary type="html">The concept of closures in Javascript can be hard to grasp at first. However, once you will have that a-ha moment, a new powerful capability of Javascript will have been revealed to you. That’s ok, because closures are considered an advanced concept of Javascript.</summary></entry><entry><title type="html">A tricky JavaScript interview using closures</title><link href="https://iulia-codes.github.io/notes/guides/javascript-interview-question-with-closure/" rel="alternate" type="text/html" title="A tricky JavaScript interview using closures" /><published>2017-01-25T00:00:00+00:00</published><updated>2017-01-25T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/guides/javascript-interview-question-with-closure</id><content type="html" xml:base="https://iulia-codes.github.io/notes/guides/javascript-interview-question-with-closure/">&lt;p&gt;Here is a tricky JavaScript interview question, that involves closures. What is the result of the following code snippet?&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;i: &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

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

&lt;p&gt;Our intuition would be that this will display the numbers from 1 to 5. But does it? The i at the end of the loop ends up with 6. By the time the functions are running, i is already 6.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The result is 6 6 6 6 6&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why don’t we have 5 different i? We seem to think that these functions are getting a whole new i for each iterations of the loop.&lt;/p&gt;

&lt;p&gt;BUT there are 5 different functions that are closing over the exact same global scope. Like writing setTimeout() one after another. 5 separate anon functions close over one scop - the global scope that has only one i in it.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;How to solve this problem such that numbers from 1 to 5 are printed?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The answer is IIFY. Functions create scope. Put a IIFY inside of the loop so that each loop gets own i.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;i: &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;})(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Result: 1 2 3 4 5&lt;/p&gt;

&lt;p&gt;Each function is closing over an iteration scope rather than the global scope.&lt;/p&gt;

&lt;h2&gt;What other tricky JavaScript interview questions do you know? Share them here!&lt;/h2&gt;

&lt;hr /&gt;</content><author><name>Iulia</name></author><category term="guides" /><category term="closure" /><category term="function" /><category term="javascript" /><category term="javascript interview" /><category term="interview question" /><summary type="html">Here is a tricky JavaScript interview question, that involves closures. What is the result of the following code snippet?</summary></entry><entry><title type="html">Build your own Skype chat bot using these simple steps</title><link href="https://iulia-codes.github.io/notes/guides/build-your-own-skype-bot-with-these-simple-steps/" rel="alternate" type="text/html" title="Build your own Skype chat bot using these simple steps" /><published>2017-01-08T00:00:00+00:00</published><updated>2017-01-08T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/guides/build-your-own-skype-bot-with-these-simple-steps</id><content type="html" xml:base="https://iulia-codes.github.io/notes/guides/build-your-own-skype-bot-with-these-simple-steps/">&lt;p&gt;&lt;a href=&quot;https://channel9.msdn.com/Events/Build/2016/B821&quot; target=&quot;_blank&quot;&gt;Build 2016&lt;/a&gt; was the first ever event to introduce chat bots, courtesy of Microsoft. If you’re wondering what a chat bot is - it is a smart bot that listens to you and performs some tasks you tell it to. Say, you want to have a bot in your chat list that will automatically send you warnings for the area you live in. Or you simply what to order a salad from your favourite restaurant. A chat bot can do this, or more.&lt;/p&gt;

&lt;p&gt;The first chat bot introduced was the Skype bot. What I like about it, is that it is crossplatform. Really, you can integrate it whereever, say Slack for example.&lt;/p&gt;

&lt;p&gt;Now, if this interests you, I suggest that you start with a bunch of theoretical notions. You need to understand what a chat bot is and what it can do. Here is a list of steps that I have put together, to get you started with writing your own bot with Skype.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;How to build a bot for Skype&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There could be no better description that the one offered by Microsoft, so I am quoting it in what follows… In the Skype developer session you will hear about some new and innovative ways we are going to enhance messaging experiences today, and into the future. Microsoft believes that adding intelligence into every day conversations will empower every person and every organization on the planet to achieve more. This is the way you’ve always wanted to communicate, but never realized it could be so easy. I’m going to show you our vision for intelligence integrated into one of the most popular ways people connect today – Skype.&lt;/p&gt;

&lt;iframe src=&quot;https://channel9.msdn.com/Events/Build/2016/T611/player&quot; width=&quot;960&quot; height=&quot;540&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;

&lt;ul&gt;
  &lt;li&gt;Build a conversational bot from 0 to 60&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Microsoft Bot Framework provides everything you need to build and connect your bots to your users wherever they converse – from SMS to Office365 mail to Slack and more… It’s your bot, wherever your users are talking. Learn how to use the Bot Framework to build a bot with your own existing code, use the Bot Builder to generate conversational dialogs from scratch, and more to give your bot skills with natural language processing and deep learning technology. Walk away with tools to build a great bot that can connect with users, wherever they are.&lt;/p&gt;

&lt;iframe src=&quot;https://channel9.msdn.com/Events/Build/2016/B821/player&quot; width=&quot;960&quot; height=&quot;540&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;

&lt;ul&gt;
  &lt;li&gt;Acquaint yourself with the bot framework&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;https://dev.botframework.com/&quot; target=&quot;_blank&quot;&gt;The bot framework &lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Get acquainted with the open source builder SDK. This SDK can be used to build Node.JS based apps, but also using the .NET framework.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Observe some cool API’s you can use&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;https://www.microsoft.com/cognitive-services/en-us/apis&quot;&gt;Microsoft cognitive services&lt;/a&gt; offers some nice options for computer vision, speech,language, text and knowledge. After watchin the two videos above, you’ll see how you can use LUIS to make your bot understand your natural language commands.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Be social, join the community&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although the community is closed, you can sign up with your skype account and pose your questions there. What is nice is that you will have answers from real people working on the real project of the SDK for Skype. So take a plunge - &lt;a href=&quot;https://community.skype.com/t5/Skype-Bot-Developers/gp-p/Bot_devs&quot; target=&quot;_blank&quot;&gt;dive into it&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;What is your next great idea for a Skype bot? Share it here!&lt;/h2&gt;

&lt;hr /&gt;</content><author><name>Iulia</name></author><category term="guides" /><category term="skype" /><category term="bot" /><category term="javascript" /><category term="microsoft" /><category term="chatbot" /><summary type="html">Build 2016 was the first ever event to introduce chat bots, courtesy of Microsoft. If you’re wondering what a chat bot is - it is a smart bot that listens to you and performs some tasks you tell it to. Say, you want to have a bot in your chat list that will automatically send you warnings for the area you live in. Or you simply what to order a salad from your favourite restaurant. A chat bot can do this, or more.</summary></entry><entry><title type="html">Adding empty folders to git versioning</title><link href="https://iulia-codes.github.io/notes/howto/adding-empty-folders-to-git-versioning/" rel="alternate" type="text/html" title="Adding empty folders to git versioning" /><published>2016-10-23T00:00:00+00:00</published><updated>2016-10-23T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/howto/adding-empty-folders-to-git-versioning</id><content type="html" xml:base="https://iulia-codes.github.io/notes/howto/adding-empty-folders-to-git-versioning/">&lt;p&gt;Today I had just started to re-organize my Thinkful FEWD course. So I have created folders with each of the units/lessons of the FrontEnd Development v6.&lt;/p&gt;

&lt;p&gt;To my surprise, when I wanted to add these folders to git, git would simply not recognize any change.&lt;/p&gt;

&lt;p&gt;The solution? Add an empty README.md file to each of the folders…and voila! Now you can upload your changes.&lt;/p&gt;</content><author><name>Iulia</name></author><category term="howto" /><category term="howto" /><category term="versioning" /><summary type="html">Today I had just started to re-organize my Thinkful FEWD course. So I have created folders with each of the units/lessons of the FrontEnd Development v6.</summary></entry><entry><title type="html">Recommended reading for computer scientists</title><link href="https://iulia-codes.github.io/notes/academia/recommended-reading-list-for-computer-science/" rel="alternate" type="text/html" title="Recommended reading for computer scientists" /><published>2016-10-13T00:00:00+00:00</published><updated>2016-10-13T00:00:00+00:00</updated><id>https://iulia-codes.github.io/notes/academia/recommended-reading-list-for-computer-science</id><content type="html" xml:base="https://iulia-codes.github.io/notes/academia/recommended-reading-list-for-computer-science/">&lt;p&gt;The world wide web is extremely rich with informations for people interested in computer science.&lt;/p&gt;

&lt;p&gt;There are different topics and as many flavours of deciding which books should be read by a computer scientist, or an aspiring one.&lt;/p&gt;

&lt;p&gt;The link is here: &lt;a href=&quot;http://olympiads.win.tue.nl/ioi/study/books.html&quot; target=&quot;_blank&quot;&gt;Recommended reading list&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What are your preferred readings and what have you read so far? Let me know in the comments!&lt;/p&gt;</content><author><name>Iulia</name></author><category term="academia" /><category term="academia" /><category term="computer science" /><category term="algorithms" /><summary type="html">The world wide web is extremely rich with informations for people interested in computer science.</summary></entry></feed>