<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Praveen Kumar Saini on Medium]]></title>
        <description><![CDATA[Stories by Praveen Kumar Saini on Medium]]></description>
        <link>https://medium.com/@am_pra_veen?source=rss-d545e1aeebfa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K03TrC0jYQ6D_2oPSQs9YQ.jpeg</url>
            <title>Stories by Praveen Kumar Saini on Medium</title>
            <link>https://medium.com/@am_pra_veen?source=rss-d545e1aeebfa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:00:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@am_pra_veen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JWT(JSON Web Token) : Implementation with Node]]></title>
            <link>https://medium.com/@am_pra_veen/jwt-json-web-token-implementation-with-node-d0661d4c7cbb?source=rss-d545e1aeebfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0661d4c7cbb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Praveen Kumar Saini]]></dc:creator>
            <pubDate>Mon, 04 Feb 2019 08:55:35 GMT</pubDate>
            <atom:updated>2019-02-04T08:55:35.155Z</atom:updated>
            <content:encoded><![CDATA[<h3>JWT(JSON Web Token) : Implementation with Node</h3><p>JSON Web Token is an open, industry-standard <a href="https://tools.ietf.org/html/rfc7519"><strong>RCF 7519</strong></a> method for authorizing transaction or requests between two parties. Basically, JWT used for the authorization purpose. We can authorize through session, cookies and third-party authorization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*IqAodJn46th31XLkU5Qf1w.jpeg" /><figcaption>Source — <a href="http://robmclarty.com/blog/what-is-a-json-web-token">http://robmclarty.com/blog/what-is-a-json-web-token</a></figcaption></figure><h4>Steps What happened basically:</h4><ul><li>The user sends the login credentials. If succeed, the server sends back a JWT token.</li><li>The sent JWT token to have to be stored in local storage.</li><li>Now, the client takes JWT and makes a request by putting JWT in Authorization header for data for the user.</li><li>The server verifies the JWT. If successful then sends the data back to the client.</li><li>After every request from the client side made by putting JWT in the authorization header.</li><li>On logout, just destroy the JWT locally.</li></ul><h3>Creation of JWT</h3><p>There’re a lot of packages but we are going to use <a href="https://www.npmjs.com/package/jsonwebtoken">jsonwebtoken</a> for creating JWT and for checking purpose we can use passport’s JWT strategy package.<br>So, we have to install <a href="https://www.npmjs.com/package/passport">passport</a>, <a href="https://www.npmjs.com/package/passport-jwt">passport-jwt</a> and <a href="https://www.npmjs.com/package/passport-local">passport-local</a>.<br>Now, It’s time to create JWT. Let’s assume that we have some user login credentials.<br>Let’s make a passport module for passport functions:</p><pre>const jwt = require(&#39;jsonwebtoken&#39;);<br>const app = require(&#39;express&#39;)();<br>const passport = require(&#39;passport&#39;);<br>const LocalStrategy = require(&#39;passport-local&#39;).Stratergy;</pre><pre>// Use Local Startergy for authenticating user <br>passport.<strong>use</strong>(<strong>new</strong> LocalStrategy(<br>  <strong>function</strong>(username, password, <strong>done</strong>) {<br>    User.findOne({ username: username }, <strong>function</strong> (err, user) {<br>      <strong>if</strong> (err) { <strong>return</strong> <strong>done</strong>(err); }<br>      <strong>if</strong> (!user) { <strong>return</strong> <strong>done</strong>(<strong>null</strong>, <strong>false</strong>); }<br>      <strong>if</strong> (!user.verifyPassword(password)) {<br>        <strong>return</strong> <strong>done</strong>(<strong>null</strong>, <strong>false</strong>);<br>      }<br>      <strong>return</strong> <strong>done</strong>(<strong>null</strong>, user);<br>    });<br>  }<br>));</pre><pre>// Apply passport authentication for getting user payload app.post(&#39;/login&#39;, (req, res, next) =&gt; {<br>  <strong>passport.authenticate</strong>(&#39;local&#39;, (err, userData) =&gt; {<br>      if (!userData || err) {<br>        return res.status(404).json({<br>          msg: &#39;Account not available. Please Sign Up.&#39;,<br>        });<br>      }<br>      <strong>req.logIn</strong>(user, (error) =&gt; {<br>        if (error) return next(error);<br>        return res.json({<br>          <strong>token: jwt.sign({user: userData}, &#39;secret&#39;),</strong><br>        });<br>      });<br>    })(req, res, next);<br>});</pre><p>When we get the token on the client side. Then it should be an encrypted string like this.<br><strong>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9</strong>.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.<em>SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c</em><br>This string contains three parts as you see above. Let’s break them down:<br>* Bold Part — Contains constructing algorithm and type of token<br>* Normal Part — Payload data it is created<br>* Italic Part — Signature (base64UrlEncode(header) + ‘.’+<br> base64UrlEncode(payload))</p><h3>Applying JWT for Authorization</h3><p>Now, we have the JWT at our client and now we have to save that in our local-storage for getting the data throughout the application. <br>Now after that, if we want to get the data of the user then we have to make a <strong>GET </strong>request by passing that JWT in <strong>authorization </strong>header:</p><pre>fetch(&#39;/user&#39;, {<br>  method: GET,<br>  headers: {<br>    &#39;Authorization&#39; : `Bearer ${localStorage.getItem(&#39;jwt&#39;)}`,<br> },<br>});</pre><p>Now, we are going to use the passport-jwt for verifying the token that is coming from the client-side.</p><pre><strong>const</strong> JwtStrategy = <strong>require</strong>(&#39;passport-jwt&#39;).Strategy;<br><strong>const</strong> ExtractJwt = <strong>require</strong>(&#39;passport-jwt&#39;).ExtractJwt;</pre><pre>// Using passport-jwt stratergy<br>passport.use(<strong>new</strong> JwtStrategy({<br>  jwtFromRequest : ExtractJwt.fromAuthHeaderAsBearerToken(),<br>  secretOrKey :&#39;secret&#39;,<br>  },<br>  <strong>function</strong>(jwt_payload, done) {<br>    User.findOne({_id: jwt_payload._id}, <strong>function</strong>(err, user) {<br>      <strong>if</strong> (err || !user) {<br>        <strong>return</strong> done(err, false);<br>      }<br>      <strong>if</strong> (user) {<br>         <strong>return</strong> done(null, user);<br>      }<br>    });<br>}));</pre><p>Now, we implemented our passport middleware and we have to just call the passport authentication method on whatever endpoint we want to authenticate.</p><pre>app.get(&#39;/user&#39;, <strong>passport.authenticate(&#39;jwt&#39;, { session: false }), </strong>(req, res) =&gt; {<br>  res.json({<br>    user: req.user<br>  });<br>});</pre><p>Finally, we implemented JWT using Node.<br>Check the code gist from <a href="https://gist.github.com/praveen-me/a10e0032b4b2331cc7df4302931b8f41">here</a>.<br>Connect me through <a href="https://github.com/praveen-me">Github</a> and <a href="https://twitter.com/am_pra_veen">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0661d4c7cbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make a Todo List Using React Hooks!!]]></title>
            <link>https://medium.com/altcampus/make-a-todo-list-using-react-hooks-d1299fdb7b0?source=rss-d545e1aeebfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1299fdb7b0</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Praveen Kumar Saini]]></dc:creator>
            <pubDate>Sun, 13 Jan 2019 05:14:53 GMT</pubDate>
            <atom:updated>2019-01-13T05:14:53.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*yCfHA67G2vPV7mmgzYpIgg.png" /></figure><p><strong>React Hooks</strong> are upcoming features in the React family and the interesting part of React Hooks are that we can use state in <strong>functional components</strong>.<br>So, no more class components it doesn’t mean the support for class components is going to be stopped there. <strong>Class components </strong>are still there.<br>But React Hooks are currently in the alpha version of <strong>React</strong> i.e <strong>v16.8.0-alpha.0</strong>. But we can use them through the alpha version.</p><h3>Setup for React Hooks</h3><p>First, we need to make a react app using <strong>create-react-app</strong>. It will make a create an app for us. For that just run in your terminalnpx create-react-app hooks-todo. It takes some time then it’ll create a react app for you now just to the app by runningcd hooks-todo now we have our <strong>react-app</strong> ready. Run npm install react@next react-dom@next that’ll install the alpha version of React in out app.</p><h3>Let’s Make the Todo</h3><p>In this project, our focus is not to make a layout. So please copy the SASS file for the project from <a href="https://gist.github.com/praveen-me/6da4e55421e61adeb91b6d9103814a7f">here</a>. If you don’t have sass package install just run npm i node-sass. <br>Now, let’s move into our App.js and make the App component <strong>functional</strong>. So, now our first move is to make the form for submitting our todo. Just copy this snippet of code into the return statement of our App component. I also called a function on events. We’ll take a look at them later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gjDdZHOgAXZ_TPoK-PJ_zg.png" /><figcaption>Todo form for adding todo</figcaption></figure><p>Now, let’s make a state for storing the current todo value. We are using useState <strong>state hook</strong> for making state. We need to import it from ‘react’.<br>For that add this line at the top of the fileimport React, { useState } from ‘react’. Now, go inside our App then add const [todoValue, setTodoValue] = useState(&#39;&#39;). So, here we are making a state <strong>todoValue </strong>and <strong>setTodoValue </strong>is for updating the value of <strong>todoValue</strong> and in the <strong>useState</strong> part, we are just setting the initial value of <strong>todoValue</strong> state by calling useState(). So, if you take a look we are using the array destructing here. <strong>useState </strong>returns an array that the first element of the array is stated name and the second item of the array is the function for updating the value of that state.<br>Now, let’s make the <strong>handleChange</strong> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3FQO1MWyEd7miYraXgJ9Q.png" /><figcaption>handleChange for setting current todo value</figcaption></figure><p>So, simple for setting the current todoValue just call the <strong>setTodoValue</strong> function and pass the value as an argument.</p><p>Now, It’s time to work on our adding todo.<br>For that, we need another state. Let’s make const [todos, setTodo] = useState([]);. So, we make another state and all our todos are going to store here. I previously made an event-handler to submitting to-do form. Let’s made a function called <strong>handleSubmit</strong> that take care of submitting todo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0i8X3wwmpbYUV3c0lmcgzQ.png" /><figcaption>function for submitting todo</figcaption></figure><p>It’s so simple from line 4 to line 7 we just making a todo object. And then in line 10 we just call <strong>setTodo</strong> function and passing a new array as an argument and the spreading the <strong>todos</strong> array for previous todos and then just adding todo at the end of the array. Now, we did our adding todo functionality we just need to display them. <br>We have to map over the <strong>todo</strong> array and make an element for every todo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V9rjJhWJzR1LqhbkohU-IA.png" /><figcaption>block for dispalying todo</figcaption></figure><p>Paste this snippet after the parent div of the App component. As you see we just map over the todos array and creating a block for every todo. I also added the event handler for adding done and delete functionality in our todo.</p><p>Let’s work on delete our todo.<br>For this, we have to make a <strong>handleDelete</strong> function. We take the id from it’s parent element of the delete button and then just going to splice that index form the array then just again called the <strong>setTodo</strong> function and make the new array and spread all todos.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MbEox6RvBCE1M1kF5H761w.png" /><figcaption>function for deleting todo</figcaption></figure><p>Now, we completed our delete todo functionality.<br>Now, let’s work on <strong>handleDone</strong> functionality of the todo. For that, let’s just create <strong>handleDone</strong> function. In that, we are going to take the id from its parent element and then change the <strong>done</strong> of that todo and set the <strong>todos</strong> using <strong>setTodo</strong> method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*saUQtUiFFCWcBpC7wLrN4w.png" /><figcaption>function for handling done of todo</figcaption></figure><p>Congrats, We completed our todo using hooks. I am glad if you make some changes and add more functionality using hooks don’t stop keep experimenting. Get the code of the App from <a href="https://gist.github.com/praveen-me/74d58161e1c863b6310d04e81e204c10">here</a>.</p><p>Follow me on <a href="https://twitter.com/am_pra_veen">Twitter</a>.<br>Check out my <a href="https://github.com/praveen-me">GitHub</a> profile.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1299fdb7b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/altcampus/make-a-todo-list-using-react-hooks-d1299fdb7b0">Make a Todo List Using React Hooks!!</a> was originally published in <a href="https://medium.com/altcampus">AltCampus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Simple SPA Routing Using Vanilla JavaScript]]></title>
            <link>https://medium.com/altcampus/implementing-simple-spa-routing-using-vanilla-javascript-53abe399bf3c?source=rss-d545e1aeebfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/53abe399bf3c</guid>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[vanilla-javascript]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Praveen Kumar Saini]]></dc:creator>
            <pubDate>Sat, 05 Jan 2019 17:21:22 GMT</pubDate>
            <atom:updated>2019-01-05T17:21:22.385Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*mHQDsqWBWs3tBrPz2uZWtA.jpeg" /><figcaption>Source — Unsplash</figcaption></figure><p>In this article, I am going to implement <strong>SPA</strong> routing using <strong>Vanilla JavaScript</strong>.<br>So, the main motive behind this article to get an understanding of how SPA routing works. Before we get into this we need to understand the main components of routing i.e Web <strong>History </strong>and <strong>Location</strong> API.</p><h3>History and Location Object</h3><p>Let’s first talk about <a href="https://developer.mozilla.org/en-US/docs/Web/API/History"><strong>window.history</strong></a>. History contains all the browser history you can simply access it by typing <em>history </em>and then you’ll get the whole history object and the variety of method’s it has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o5aivA_EwWECOOZnq2GYog.png" /><figcaption>window’s history object</figcaption></figure><p>And another one that we are going to use is <a href="https://developer.mozilla.org/en-US/docs/Web/API/Location"><strong>window.location</strong></a><strong>. </strong>It contains all the information about the current location such as origin, pathname, etc. If you type <em>location</em> in your terminal then you got the whole location object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GHosXKQnj5bwM8x3jo8wKQ.png" /><figcaption>window’s location object</figcaption></figure><h3>Let’s start Routing</h3><p>So, first of all, we need to make an <strong>index.html.</strong> It contains all the markup for our app. For this right, we just need to make a div of the <em>id </em>of <strong>root</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gbW54Pe4_GxHFe4hxB0V8w.png" /><figcaption>index.html</figcaption></figure><p>Now, we are done with that make our page. That is going to render in <strong>root</strong> area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FbzwL2Qa7-_o2CXBgHmTyA.png" /><figcaption>Our three different components</figcaption></figure><p>Now, we make our three different pages let’s import them in our index.html’s <strong>head </strong>section. Now we have to use a server to serve these pages so in this I am going to use <strong>live-server</strong>. If you have live-server it’s well and good just go to the folder directory and run live-server otherwise install it using npm i -g live-server.<br>Now, it’s time to make our main JavaScript file that contains all our routing logic.<br>Let&#39;s make a file called app.js. <br>Then first we have to decide our routes and page specific to that particular route and put them in an object.</p><pre><em>const</em> routes = {<br>  &#39;<em>/</em>&#39;<em> </em>: home,<br>  &#39;<em>/contact</em>&#39;<em> </em>: contact,<br>  &#39;<em>/about</em>&#39;<em> </em>: about<br>};</pre><p>Our next work is to render a page when the index initially loaded. For that first, we have to select the <strong>root</strong> div and then use innerHTML method to add the content to the element according to the path.</p><pre><em>const</em> rootDiv = document.getElementById(&#39;<em>root</em>&#39;);<br>rootDiv.innerHTML = routes[window.location.pathname];</pre><p>Here <strong>window.location.pathname </strong>will give the current path and when the page is loaded the current path is going to <strong><em>‘/’</em></strong><em>. </em>But our work is not done here yet. Now, we also have to make the route for ‘/about’ and ‘/contact’ page. For that, we are going to create a simple navigation menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HRolE_-GnyX2C7o-ye5ZIQ.png" /><figcaption>Simple navigation for navigating through sections.</figcaption></figure><p>Now, we are going to make a function that helps us to navigate through section it takes a path and then uses <strong>history.pushState() </strong>method that takes three parameters i.e state, title, and the route to push and to push the current route into history object so we can also navigate through the browser <em>backward</em> and <em>forward</em> button and then render the section according to the current path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nok3v9iCyS75U1G0dgWHow.png" /><figcaption>onNavigate Method</figcaption></figure><p>Now, just call this <strong>onNavigate </strong>method on the <strong>onClick </strong>event of our navigation menu’s a tag. We just need to do this.</p><pre>&lt;a <em>href</em>=&quot;<em>#</em>&quot; <em>onclick</em>=&quot;<em>onNavigate(</em>&#39;<em>/about</em>&#39;<em>)</em>;<em> return false</em>;&quot;&gt;About&lt;/a&gt;<br>// repeat for other routes also.</pre><p>Congrats you just make your own router and when you pressing browser’s forward and backword button you see that the route actually changes but wait for your page is not changing. So, this is because when the browser call’s it’s <strong>pushState()</strong> method than another method is also called i.e <strong>window.onpopstate</strong> it’s a simple function where you can customize it according to your need. So, whenever the pushState is called we are going to render our section. For that all we need to apply this.</p><pre>window.onpopstate = () <em>=&gt;</em> {<br>  rootDiv.innerHTML = routes[window.location.pathname]<br>}</pre><p>Congrats you finally have done with it.</p><p>If you want to follow the code. Check out GitHub repo from <a href="https://github.com/praveen-me/simple-vanila-router">here</a>.<br>If you want to connect with me check out my <a href="https://twitter.com/am_pra_veen">Twitter</a> and <a href="https://github.com/praveen-me">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53abe399bf3c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/altcampus/implementing-simple-spa-routing-using-vanilla-javascript-53abe399bf3c">Implementing Simple SPA Routing Using Vanilla JavaScript</a> was originally published in <a href="https://medium.com/altcampus">AltCampus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do Static Routing with Node]]></title>
            <link>https://medium.com/altcampus/do-static-routing-with-node-c86fcca4589b?source=rss-d545e1aeebfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/c86fcca4589b</guid>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[newbie]]></category>
            <dc:creator><![CDATA[Praveen Kumar Saini]]></dc:creator>
            <pubDate>Mon, 03 Dec 2018 18:05:18 GMT</pubDate>
            <atom:updated>2018-12-03T18:05:18.943Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*2EeBPk5GJynWPjD1AuuPgw.jpeg" /><figcaption>Unsplash — <a href="https://unsplash.com/@markusspiske">Markus Spiske</a></figcaption></figure><p>So, first of all, why am I writing this because of when I started <strong>Node</strong> couple of days back, I got just frustrated with searching about how can I do static routing using Node but I can’t find anything good and I just go through every question of <strong>Stack Overflow </strong>but I can’t find anything good and everyone is talking about <strong>Express </strong>in every question it doesn’t matter whether the guy that asks the question only about in <strong>Node</strong>. <br>So, first of all, let’s talk about static routing.</p><h3>What is Static Routing?</h3><p>So, Static Routing is that kind of routing where we to set a router manually for a specific route. There are some demerits of it like everytime if we have a new file then we have set route for that file manually. And also it’s hard to handle the route for every file in our project.</p><h3>Serve Static Files</h3><p>So, let’s start routing i.e start making routes and serve files according to it.<br>So, we have our routes like this:-<br>* “/”<strong> — index.html<br>* </strong>“/about” — <strong>about.html<br>* </strong>“/contact” — <strong>contact.html<br>* </strong>“/public/stylesheet/style.css” — <strong>style.css<br>* </strong>“/public/images/1.jpg” — <strong>1.jpg<br>* </strong>“/public/images/2.png” — <strong>2.png</strong></p><p>And we have the directory like this:-</p><pre>public/<br>  |<br>  -&gt; index.html<br>  -&gt; about.html<br>  -&gt; contact.html<br>  -&gt; stylesheet/<br>        |<br>        -&gt; style.css<br>  -&gt; images/<br>        |<br>        -&gt; 1.jpg<br>        -&gt; 2.png<br>  |<br>  index.js</pre><p>So, first we have to create our server first:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e7oNU6yQMqDXJfGepEBXkA.png" /><figcaption>Created Server</figcaption></figure><p>Now, we created our server so we need <strong>fs </strong>package. Then we have to take the benefit of <strong>Node JS</strong> <strong><em>request </em></strong>object that contains two special property i.e <strong>url </strong>and <strong>method. </strong>The <em>request.method </em>gave us the method of the request and <em>request.url </em>will give us the browser’s request URL that the browser requested for. Now it’s time to check for the URL and method and serve the static pages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kA67K--nS6Dki-P2uODhSg.png" /><figcaption>Make a route and render file according to it.</figcaption></figure><p>And follow the above same steps and every time just change the <strong>case</strong> and read the file for that specific kind and just change the header every time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oT3nyg9uGdmWpazzgsWZ0g.png" /><figcaption>Headers for specific files</figcaption></figure><p>So, you have done your static routing with node. 😄</p><p>Follow me on <a href="https://twitter.com/am_pra_veen">Twitter</a>.<br>Follow me on <a href="https://github.com/praveen-me">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c86fcca4589b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/altcampus/do-static-routing-with-node-c86fcca4589b">Do Static Routing with Node</a> was originally published in <a href="https://medium.com/altcampus">AltCampus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Classes: Let’s Know Behind the Scenes]]></title>
            <link>https://medium.com/altcampus/javascript-classes-lets-know-behind-the-scenes-f7b69ffafcf0?source=rss-d545e1aeebfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7b69ffafcf0</guid>
            <category><![CDATA[newbie]]></category>
            <category><![CDATA[javascript-class]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Praveen Kumar Saini]]></dc:creator>
            <pubDate>Fri, 30 Nov 2018 03:51:45 GMT</pubDate>
            <atom:updated>2018-11-30T03:51:45.466Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*H-pLl9S63QJl49ad8Fa-tg.jpeg" /><figcaption>Unsplash Image By Nam Hoang</figcaption></figure><p>So, as we know <strong>JavaScript Classes</strong> are just a way of working on our problem using the OOP paradigm that helps us to solve our problem in a very structured way. In this article, I am not going to tell you how to write a <strong>JavaScript Classes</strong> my main focus is just to implement in different approaches.<br>In this article we are going to implement <strong>JavaScript Classes</strong> in three ways:-<br>* <strong>Using Factory functions</strong><br>* <strong>Using Constructor Function (Pseudo Class)</strong><br>* <strong>Using Classes</strong><br>So, let’s start.</p><h3>Using Factories Functions</h3><p>As I wrote we are going to implement by <strong>factories function</strong>. Let’s first talk about what are <strong>factories functions</strong>.<br><strong>Factories functions </strong>are simple functions that take values from and returns an object to you they are not <strong>constructor</strong> functions. We just have to call them and they just return us an object and we can store these object in any variable.<br>Now, we going to apply our <strong>class</strong> using these <strong>factories functions</strong>.<br>Let’s first make an object that holds the function that is linked with the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto"><strong>[[Prototype]]</strong></a><strong> </strong>of the<strong> </strong>object.</p><pre>let studFunctions = {<br>  percentage: function(p, c, m) {<br>    let total = p + c + m;<br>    console.log((total / 3).toFixed(2));<br>  },<br>  result: function(p, c, m) {<br>    let total = p + c + m;<br>    if(total &gt; 50){<br>      console.log(&quot;Pass&quot;);<br>    } else {<br>      console.log(&quot;Fail&quot;);<br>    } <br>  }<br>}</pre><p>Here we created an object that has two methods <strong>percentage</strong> and <strong>result</strong> for our <strong>Student </strong>object.<br>Now, let’s create a factory function that creates an object for us and return it.</p><pre>function studFactory(p,c,m) {<br>  let obj = Object.create(studFunctions);<br>  obj.phy = p;<br>  obj.che = c;<br>  obj.math = m;<br>  <em>return</em> obj;<br>}</pre><p>So, here we created a function that takes send three parameters and then we created an object using <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/create"><strong>Object.create()</strong></a><strong> </strong>because of this method us to create an empty object and set the <strong>[[Prototype]] </strong>to the <strong>studFunctions </strong>that we created. Now, we created our class now it’s time to create instances with this class.</p><pre>let stud1 = studFactory(50, 60, 80);<br>stud1.percentage(stud1.phy, stud1.che,stud1.math); // 63.33<br>stud1.result(stud1.phy, stud1.che, stud1.math); // pass</pre><h3>Using Constructor Function (Pseudo Class)</h3><p>Now it turns to make the class using the pseudo-class method. For that first, we have to create a constructor function for that.</p><pre>function Student (p, c, m) {<br>  <em>this</em>.phy = p;<br>  <em>this</em>.che = c;<br>  <em>this</em>.math = m;<br>}</pre><p>So, we just here created a function that takes three parameters and inside that <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/this"><strong>this</strong></a><strong> </strong>because in the after some time we are going to call this function with <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/new"><strong>new</strong></a><strong> </strong>operator that returns an object from that function and then <strong>this</strong> refers to that same object.<br>Now we are putting some function in the <strong>prototype </strong>of the function. <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype"><strong>Prototype</strong></a> is just a simple object that default attach with the function and contains a contains a default <strong>constructor </strong>property that points to the same function.</p><pre>Student.prototype.percentage = function() {<br>  let total =  <em>this</em>.phy + <em>this</em>.che + <em>this</em>.math;<br>  console.log((total / 3).toFixed(2))0<br>}</pre><pre>Student.prototype.result = function() {<br>  let total =  <em>this</em>.phy + <em>this</em>.che + <em>this</em>.math;<br>  <em>if</em>(total &gt; 200) {<br>    console.log(&#39;pass&#39;);<br>  } <em>else</em> {<br>    console.log(&#39;fail&#39;)<br>  }<br>}</pre><p>So, same as previously did we did same just putting the method in the prototype of the function.<br>We created our class. Now let’s just make an instance from this class.</p><pre>let stud1 = new Student(60, 90, 80);<br>stud1.result(); //76.67<br>stud1.percentage(); // &#39;pass&#39;</pre><h3>Using Classes (ES6 classes)</h3><p>Now finally, we are going to implement <strong>JavaScript classes </strong>using ES6 classes.<br>For that, we just have first had to put <strong>class </strong>keyword in front Class name inside that there’s a special <strong>constructor</strong> method where we just going to put values as we did in previously where we make constructor function. Then just simply put the method that we put in the <strong>prototype </strong>in the previous section.</p><pre>class Student {<br>  constructor(p, c, m) {<br>    <em>this</em>.phy = p;<br>    <em>this</em>.che = c;<br>    <em>this</em>.math = m;<br> }</pre><pre> percentage() {<br>   let total =  <em>this</em>.phy + <em>this</em>.che + <em>this</em>.math;<br>   console.log((total / 3).toFixed(2));<br> }</pre><pre> result() {<br>   let total =  <em>this</em>.phy + <em>this</em>.che + <em>this</em>.math;<br>   <em>if</em>(total &gt; 200) {<br>     console.log(&#39;pass&#39;);<br>   } <em>else</em> {<br>     console.log(&#39;fail&#39;)<br>   }<br> }<br>}</pre><p>Finally, we created our class with ES6 class syntax also. Now just initiate our class as we previously did in <strong>pseudo class</strong> part.</p><pre>let stud1 = new Student(60, 90, 80);<br>stud1.result(); //76.67<br>stud1.percentage(); // &#39;pass&#39;</pre><h3><strong>Conclusion</strong></h3><p>So, If you compare all these three approaches to writing <strong>JavaScript class </strong>then you the last step of making classes easier and cleaner way. But the motive of this article is just to demonstrate how it works behind the scenes i.e if we broke down to make a class into smaller parts then <strong>factory functions </strong>approach makes gave you an idea how it works.</p><p>Follow me on Twitter.<br>Follow me on <a href="https://github.com/praveen-me">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7b69ffafcf0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/altcampus/javascript-classes-lets-know-behind-the-scenes-f7b69ffafcf0">JavaScript Classes: Let’s Know Behind the Scenes</a> was originally published in <a href="https://medium.com/altcampus">AltCampus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux Thunk: A Simple Action Creator Nothing More.]]></title>
            <link>https://medium.com/altcampus/redux-thunk-a-simple-action-creator-nothing-more-7111eae22379?source=rss-d545e1aeebfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/7111eae22379</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[code-newbie]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <dc:creator><![CDATA[Praveen Kumar Saini]]></dc:creator>
            <pubDate>Sun, 18 Nov 2018 13:34:19 GMT</pubDate>
            <atom:updated>2018-11-18T13:34:19.811Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*fYNnF7z5Tl8Q6jWeFNKC9w.jpeg" /><figcaption><a href="https://images.unsplash.com/photo-1508522109214-4df07c2e9d90?ixlib=rb-0.3.5&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;s=74d606b8155eae1512bccc3cdbebd19c&amp;auto=format&amp;fit=crop&amp;w=750&amp;q=80">https://images.unsplash.com/photo-1508522109214-4df07c2e9d90</a></figcaption></figure><p>So, I am going to talk about a really interesting topic i.e <strong>Redux Thunk.</strong> So first, if you are a beginner in redux and want to learn what does actually <strong>redux thunk </strong>is and why should you use it and by the end of the article you have a good understanding of <strong>Redux Thunk</strong>. So, before moving directly to <strong>redux thunk</strong> let’s just first talk about <strong>Action Creator</strong> in Redux.</p><h3><strong>What is Action Creator?</strong></h3><p>So, In Redux <strong>action</strong> is some kind of event that is triggered on a specific situation. Suppose, the user clicks a button then the user just want to perform some action. So, As you know that according to the <strong>paradigm of</strong> <strong>redux </strong>whenever you want to perform some action then you have to dispatch that action. And when you are dispatching that action you can send any kind of data with it. So, action creator is a simple function that takes data and dispatch inside itself. And you can import that <strong>action creator</strong> and map dispatch function to props using <strong>connect </strong><em>higher-order component</em> from <strong>react-redux</strong> package. Then all you need is that just handle that event and call that <strong>action creator </strong>from props and pass the specified data into it. So, that means <strong>action creator </strong>only need that data you want to send when going to do everything for you.<br>Now, let’s just talk about what is <strong>Redux Thunk.</strong></p><h3>What is Redux Thunk?</h3><p>So, as I mentioned <strong>redux thunk</strong> is just an action creator with some extra power that helps us to deal with asynchronous calls. So, before you want to use <strong>redux thunk</strong> you have to know what is it actually. <strong>Redux Thunk</strong> is a <strong>middleware </strong>(middleware is some kind of code that runs b/w two main phases of <strong>redux paradigm</strong> i.e dispatching an action and taking that action to the reducer) that has a functionality of pausing and resuming the dispatch action. So, what is actually does when we dispatch an action creator it just takes data and perform some async call for that time until it gets the <strong>response</strong> it’s pause the dispatching of that action there and if it gets the <strong>response</strong> and then it going to resuming that dispatching that action and then goes to <strong>reducer</strong>.</p><h3><strong>How to use a Redux Thunk?</strong></h3><p>So, if you want to use the <strong>redux thunk </strong>then you have to install a <strong>redux-thunk </strong>package and import <strong>thunk</strong> from it.</p><pre><em>import</em> thunk <em>from</em> &quot;redux-thunk&quot;;</pre><p>Now you got the redux thunk. Now you have to import <strong>applyMiddlware, </strong>and<strong> compose </strong>from <strong>redux </strong>package.</p><pre><em>import</em> { createStore, applyMiddleware, compose } <em>from</em> &#39;redux&#39;;</pre><p>Now you have that. So, go to that file where you created your store and pass <strong>compose </strong>as the second parameter besides the <strong>rootReducer </strong>and inside that call <strong>applyMiddlware </strong>and pass <strong>thunk </strong>inside it.</p><pre>const store = createStore(rootReducer,   compose(applyMiddleware(thunk)));</pre><p>So, now you just add thunk to your project and you can create your own <strong>thunk</strong> now. I am here making a simple thunk that helps you to make just a better understanding of <strong>thunk</strong>.<br>So, suppose you want an app where you just gave a Github username and it will give you the whole data when you submit a form.<br>So, let’s just make a simple thunk i.e a function called <strong>setUserData </strong>that takes the only username when the user is submitting a form.</p><pre>const setUserData = (username) =&gt; {<br>  return (dispatch) =&gt; {<br>    fetch(`https://api.github.com/users/${username}`)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; {<br>         dispatch({type : &quot;SET_USER_DATA&quot;, userData : data});<br>      }).catch(error =&gt; {<br>         dispatch({type : &quot;SET_USER_ERR&quot;, error : error});<br>     })<br>    }<br>}</pre><p>So, we just make <strong>thunk</strong> so what it does it takes a username and fetch the <strong>userData</strong> and when it has the response it just resuming the dispatching of action.<br>Now, I made this thunk, how can I use this.<br>So, All you need is just you have to import the <strong>thunk</strong> in the component you want to send the data.<br>So, for that, you have to import <strong>connect </strong><em>higher-order component</em> form <strong>react-redux.</strong></p><pre>import {connect} from &#39;react-redux&#39;;<br>import setUserData from &#39;./thunk&#39;;</pre><p>Then you have to call it like you want to use store in the component to change the view and you have to make a function that map <strong>dispatch </strong>into props.</p><pre>function mapDispatchToProps(dispatch) {<br>   return {<br>    setUserData : (username) =&gt; dispatch(setUserData(username));<br>   }<br>}</pre><pre>export default connect(null, mapDispatchToProps)(Form);</pre><p>So, now all you need is just call the <strong>setUserData </strong>function from props when you are going to handle that event.<br>You can do like this.</p><pre>handleSubmit = (e) =&gt; {<br>   const userName = this.state.username;<br>   this.props.setUserData(userName);<br>}</pre><p>So, this all we need to apply a <strong>Redux Thunk</strong>.</p><h3>Benefits of Using Redux Thunk</h3><p>So, normally an <strong>action creator</strong> is returning an object but in case of <strong>thunk</strong> it returns and function where you can do some asynchronous work and when that work is done then from that function you can return the object by calling dispatch method. <strong>Thunk </strong>is a middleware that means you can perform anything before the action is going to the reducer but it’s ideal for asynchronous work.</p><p>Follow me on <a href="https://twitter/am_prav_veen">twitter</a>.<br>Follow me on <a href="https://github.com/praveen-me">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7111eae22379" width="1" height="1" alt=""><hr><p><a href="https://medium.com/altcampus/redux-thunk-a-simple-action-creator-nothing-more-7111eae22379">Redux Thunk: A Simple Action Creator Nothing More.</a> was originally published in <a href="https://medium.com/altcampus">AltCampus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scope: Local, Global and Lexical]]></title>
            <link>https://medium.com/altcampus/scope-local-global-and-lexical-e164f53450b3?source=rss-d545e1aeebfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/e164f53450b3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[scopes]]></category>
            <category><![CDATA[beginner-javascript]]></category>
            <dc:creator><![CDATA[Praveen Kumar Saini]]></dc:creator>
            <pubDate>Thu, 06 Sep 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-09-06T07:01:54.452Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*b92ypc_3zspCRuha.png" /></figure><p><strong>A scope</strong> is like a limited area. Scopes are the essential part of every programming language. They are behaving like a limited space for a declaration i.e where every variable is declared and what part of the program that variable can be accessed.</p><p>As <a href="https://developer.mozilla.org/en-US/docs/Glossary/Scope">MDN</a> Says — <strong>The context in which values and expressions are “visible,” or can be referenced.</strong></p><p>There are two types of scopes:-</p><ul><li>Global Scope</li><li>Local Scope <br> But I also going to talk about <strong>Lexical Scope</strong>.</li></ul><h3>What is Global Scope?</h3><p>Global Scope is a term used when a variable is declared outside any of the functions i.e the variables should be declared globally.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d31470b5ffdb6ea47380462d60e1a91f/href">https://medium.com/media/d31470b5ffdb6ea47380462d60e1a91f/href</a></iframe><p>So, If you look at the above function there’s variable <strong>a</strong> is declared globally and it can be accessed inside the function. Here, <strong>iAmLocal()</strong> function created its own scope. But here’s the variable is declared in global scope. So, the point is that if we declared a variable globally it can be accessed inside a function.</p><p>Let&#39;s take another example:-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ed4475739d1d3597c8e0c0a2225a1f3/href">https://medium.com/media/8ed4475739d1d3597c8e0c0a2225a1f3/href</a></iframe><p>So, the value of the variable should be changed or not. Let’s know it by executing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gYbVqMpscLSHgq5K.png" /></figure><p>It changed because the variable <strong>a</strong> is accessible inside the function because it is declared globally. So, when we call the <strong>IAmLocal()</strong> function, that reassigned the value of <strong>a</strong> again. Now, let’s go to local scope.</p><h3>What is Local Scope?</h3><p>When we declare a function it creates its own scope. So, whenever a function is declared it creates its local scope which is limited to that function. So, it means that if you are declared a variable inside a function it’s limited to it. So, Let’s understand it by a code example:-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7b4663e506945cfc03da7d2ff7a40a3/href">https://medium.com/media/a7b4663e506945cfc03da7d2ff7a40a3/href</a></iframe><p>Let’s access the variable outside the function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*BdTnoZybU23OBJiV.png" /></figure><p>OOPS!! It says an error because now the engine looks for the variable <strong>b</strong> globally but it can’t find the value because it is declared in the <strong>iAmLocal()</strong>. So, that’s why it returns an <strong>error</strong>.</p><p>Let’s take another example:-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/936333ada3e28a4901f4d4fec3fc43b8/href">https://medium.com/media/936333ada3e28a4901f4d4fec3fc43b8/href</a></iframe><p>So, can we access <strong>a</strong> inside the <strong>secondNumber()</strong>. Let’s try it by running it. If we get <strong>15</strong>, that means we can.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hz7apAaSbtZ1py_3.png" /></figure><p>Yes, It is.</p><h3>Why is that happen?</h3><p>Because when <strong>sum()</strong> is declared it creates its own scope and the variables that are declared inside it can be accessible limited to the scope of the <strong>sum()</strong>. But when we declaring the <strong>secondNumber()</strong> function inside the <strong>sum()</strong> it also creates its own scope. So, when we called <strong>secondNumber()</strong> it gonna look for the value of <strong>a</strong>. It doesn’t find <strong>a</strong> it goes to it parent and checks if there’s <strong>a</strong> is not. Ya, It’s find there and execute that value successfully.</p><h3>== Lexical Scope ==</h3><p>So, Lexical Scope is the same as the nested local scopes but there be little bit difference between them. In this, if the current scope doesn’t find the value then it moves outside to that scope and tries to find the value there. This process continues until it finds the value. Let’s do it by an example:-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f3026eab22c70920af2f4934a53ee8a/href">https://medium.com/media/6f3026eab22c70920af2f4934a53ee8a/href</a></iframe><p>So, In the above code sample, I declared <strong>num1</strong> globally because it’s outside all the loops. Now, when we declared the <strong>add()</strong> function it creates it’s own scope. That’s why <strong>num2</strong> is declared locally so it available in the scope of the <strong>add()</strong> function. So, let’s think and look the code carefully that it gives us the <strong>13</strong> or not. <br> Let’s execute it:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/0*C7L8i_uPeEWAs3Xw.png" /></figure><p><strong><em>So, what happened here?</em></strong> <br> Let’s go on that line where we called the <strong>add()</strong> and stored this in the variable called <strong>addIt()</strong>. So, now <strong>addIt()</strong> holds the return function that is returned by the <strong>add()</strong> function and when we call the returned function we got the correct answer. So, the thing is that how can it access the value of <strong>num1</strong>. So, I write above that if the variable doesn’t find it’s value inside that function so it bubbles out i.e it goes upwards. So, now in the function that is returned by the <strong>add()</strong> function. Now, <strong>num1</strong> finds that is my value presented in this scope if it doesn’t so it moves in the scope of the <strong>add()</strong> and checks it that my value is presented here or not. No, It goes to the global scope where it finds the value and executes it. So, the process of bubbling out and finding it’s value is called <strong>lexical scope</strong>. <br> If it doesn’t find the value then it returns an error saying that variable is not defined.</p><h3>Let &amp; Const -&gt; How They Effect Scope</h3><p>So, let and const are new members in the family of variables declarations in JavaScript. So, they help us to create a scope and helps the variable to not get hoisted. Let’s take an example:-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9e19637948aac984a96779d2b73a0a1/href">https://medium.com/media/e9e19637948aac984a96779d2b73a0a1/href</a></iframe><p>Let’s check out it:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/0*fY4-jWneHGHt0pOj.png" /></figure><p>So, we can access the variable <strong>i</strong> outside the loop because we know that only function can create their own scope. So, <strong>for loop</strong> declared in the global scope. That’s why in the last when the loop got executed we got the increased value of <strong>i</strong>.<br>Let’s do it again but put <strong>let</strong> instead of <strong>var</strong> :-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84390599e9e516c1717a0cb685d7bbe6/href">https://medium.com/media/84390599e9e516c1717a0cb685d7bbe6/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*Xr4qxHLAG4TfWen_V3idkw.png" /></figure><p>Ya, it said a <strong>error</strong> saying <strong><em>i</em></strong><em> is not defined</em> because <strong>let</strong> creates a scope to that variable. <br><strong>const</strong> is also same as the <strong>let</strong> but you can’t reassign a value again. So, assigning value with <strong>var</strong>, <strong>let</strong> and <strong>const</strong> depends on your need that you want to access that variable locally or want to update the variable as value reassigned to it.</p><p>Thanks for reading…</p><p>Follow me on <a href="https://twitter.com/am_pra_veen"><strong>Twitter</strong></a> and check all these Gists on <a href="https://gist.github.com/praveen-me"><strong>GitHub</strong></a>.</p><p><em>Originally published at </em><a href="https://praveen-me.github.io/blog/javascript-scopes"><em>https://praveen-me.github.io/blog/javascript-scopes</em></a><em> on September 6, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e164f53450b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/altcampus/scope-local-global-and-lexical-e164f53450b3">Scope: Local, Global and Lexical</a> was originally published in <a href="https://medium.com/altcampus">AltCampus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Udacity gave more confidence to me?]]></title>
            <link>https://medium.com/@am_pra_veen/how-udacity-gave-more-confidence-to-me-c1f46c056b86?source=rss-d545e1aeebfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1f46c056b86</guid>
            <category><![CDATA[google-india-scholarship]]></category>
            <category><![CDATA[confidence]]></category>
            <category><![CDATA[udacity]]></category>
            <dc:creator><![CDATA[Praveen Kumar Saini]]></dc:creator>
            <pubDate>Mon, 07 May 2018 13:12:45 GMT</pubDate>
            <atom:updated>2018-05-07T14:59:41.313Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>**The Google </em></strong><a href="https://udacity.com/"><strong><em>Udacity</em></strong></a><strong><em> India Scholarship**</em></strong></p><p>Hey Guys, <br>There’s nothing new in this but you found something special I thought that hold you guys to think for a sec. I am not good a writing .<br>This Scholarships give me hope for that <strong>Why should I code</strong> because before this I just code it’s just like hobby to me.<br>So, this story takes only 5 minutes of your precious time and I am sorry all of you for that. My grammar is not quite good.And I hope it be quite interesting for you. So, Here’s my story start.</p><h4>How I got knew about this program?</h4><p>In the late December, I surf to the <a href="https://udacity.com/">Udacity</a> and read the blog of the <a href="https://udacity.com/">Udacity </a>which are quite inspiring and I have a regular habit to read the blogs.<br>I surf over the blog and I saw something that is for me. I saw that Google got collaborate with <a href="https://udacity.com/">Udacity</a> and announces 30000 scholarships for <br><em>Mobile and Web Development</em>. And I passionate about <strong>Web Development</strong> so without wasting time to think about think I surf the application and view <br>what they need and I saw something about that need a Github Reposritry(It’s optional) but I don’t want to loose any chance to this scholarship So<br>I thinking some and write my repo and in the late January I submit the form. I filled my form based for Front-End Track.</p><h4>That day came When I got my most beloved mail till now.</h4><p>They said that the result got out on<em> Feb 8</em> and recipients got email about that But out on the <em>Feb 7</em> and It said that your application got accepted for <br>Front-End Track and the classes start from <em>Feb 14</em>. It’s just like that I got the chance to prove myself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*VJ2NqVfjNExtzypPX9gceQ.png" /><figcaption>That Best Mail I got</figcaption></figure><h4>The Day when classes get started.</h4><p>I called an ISP vendor and take a connection of Internet because before I used my friend’s <em>JIO</em>. So, Thanks <a href="https://udacity.com/">Udacity</a>, now I have unlimited data. 😄<br>It’s the morning of Feb 14 and sit on my P.C and excited about the classes and the cohort of the program. I played the first video of the program in that<br>They said that there’s something called <em>Slack</em> and <em>Discussion Forum</em>(I knew about it) but I don’t about<em> Slack</em> and thought what this on the starting 2–3 days the link to slack is not opened yet.</p><h4>The Time When Everything got Setup.</h4><p>Now, It’s the time when <em>Slack</em> got opened properly and I see that I just like an chatting app and through we got easily interacted with our cohort member.<br>And There’s discussion forum also where we can ask questions and answer the others question. And I liked it because I like to answer queries of others.<br>So, I answer others questions and also ask my queries. I answer as best I can.<br>Here’s my currently discussion forum progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nbaUj6Lci132GyCEsAUxOg.png" /><figcaption>My Discussion Forum Progress</figcaption></figure><p>And Now, I talked about Slack. I got addicted to it. It’s just like a habit to me to ask and answer and knew new stuff that I don’t know yet. <br>It’s just like a medicine dose to me like You have to take it after wake up in morning and also take before you go to bed. 😆</p><p>And, After some days <a href="https://medium.com/u/ecfa0eae2974"><em>Akshit Jain</em></a><em> Sir </em>made announcement that anyone who wants to be a moderators just fill out a form. Without wasting the time I applied for moderator.</p><p>And After some days I got a message form <a href="https://medium.com/u/ecfa0eae2974"><em>Akshit Jain</em></a><em> Sir </em>to be a moderator of <em>#live_help_official</em>(It’s the channel where a live help session is conducted twice a week). It also just like a appreciation for me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*5PB_tkI7cSUbaylBF5FVBQ.png" /><figcaption>The post after end by<strong> Iip Sir</strong>.</figcaption></figure><p>And Now, my work start because as a moderators to help <br><em>Iip Permana Sir(</em><a href="http://twitter.com/iip"><em>@iip</em></a><em>.udacity)</em> to take sessions. And It’s just like to work with a expert and help him. And after some time <em>Iip Permana Sir(</em><a href="http://twitter.com/iip"><em>@iip</em></a><em>.udacity) </em>mentions my name in his good bye post before the session got over. It’s also kind of appreciation to me.</p><h4>One more Important announcement which gives a chance to **BE**.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*QLa0bIRpglEVVZ8kFzUhTg.png" /><figcaption>Mail got for Google I/O.</figcaption></figure><p>Now, In at March 23 <a href="https://medium.com/u/ecfa0eae2974"><em>Akshit Jain</em></a><em> Sir</em> made a another announcement in that He said that we got some surprise email. <br>I check my mail without wasting the time. And a mail came from **Udacity India**. The mail said that win a chance for Google I/O and in that they told that for this you have to complete your challenge course by 80% percent.</p><p>At that time I completed 60% and I looked at the date there are 5 days to me and now I try to complete 80% by 28 May. And I complete and filled the form.<br>Now, I eagerly wait for the mail and at April 2 I got the mail from <a href="https://medium.com/u/ecfa0eae2974"><em>Akshit Jain</em></a><em> Sir</em> in that He said <strong><em>“You might need a chair somewhere near you so that you can sit and see the news I have got for you in this email.”</em></strong> and <strong><em>“Congratulations! You have been selected as one of the waitlist participants for the trip to Google #IO18 on behalf of Google and Udacity.”</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7hsfXmpbvVovGtd6bQWc-Q.png" /><figcaption>That mail I got from<strong> Akshit Sir </strong>on the behalf of Google I/O</figcaption></figure><p>It’s just like a daydream to me but there’s a problem in this <strong><em>**I am not 18 yet and there’s only 2 months left to me for completing 18**</em></strong>. So, I told <a href="https://medium.com/u/ecfa0eae2974"><em>Akshit Jain</em></a><em> Sir</em> about that But according to the terms of the contest I am have to be 18.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*YMhs9LJMxazdOFjRaoZyqw.png" /><figcaption>Message That I got By <strong>Akshit Sir</strong> after asking about this situation.</figcaption></figure><h4>About Mentor of Our Program</h4><p><a href="https://medium.com/u/ecfa0eae2974"><em>Akshit Jain</em></a><em> Sir</em> — He’s the mentor of the slack and all work in slack under him. He never late to reply my answer. And the best quality of him that he’s very polite.</p><p><em>Iip Permana Sir(</em><a href="http://twitter.com/iip"><em>@iip</em></a><em>.udacity)</em> — He’s the mentor for #live_help_session channel. He never left anyone post without replying anybody.</p><p><em>Avi(</em><a href="http://twitter.com/aviaryan"><em>@aviaryan</em></a><em>)</em>— He’s the forum mentor and best. Whenever he replies with a perfect reason behind it.</p><h4>About my Cohort</h4><p>I thanked <a href="https://udacity.com/"><strong>Udacity</strong></a> for this amazing cohort. They just like dying for help others. As well as in <em>Forum</em> or in <em>Slack</em> someone ask any query on any base I surely tell you won’t be disappointed. Even in night at any time you want to ask there are many night crow who are always waked and ready for help.<br>I don’t know how can they do that 😜. That’s the reason behind I got addicted to this community.</p><h4>At last, Covert <strong>HOPE INTO OPPORTUNITY</strong></h4><p>As I mentioned in this title. Convert your <em>Hope</em> in <em>Opportunity</em> because first you have some hope for doing better then it is in you hand to make a opportunity for you or not. <em>Opportunity </em>don’t came to you directly first it gives you some hope.</p><p><strong>Thanks all of you that you guys gave some time to look at this. 😃</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1f46c056b86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>