<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sunny Praksah</title>
    <description>The latest articles on DEV Community by Sunny Praksah (@sprakash57).</description>
    <link>https://dev.to/sprakash57</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F254060%2Fd751fd24-b615-47ff-99cf-bbc3269504d5.jpeg</url>
      <title>DEV Community: Sunny Praksah</title>
      <link>https://dev.to/sprakash57</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sprakash57"/>
    <language>en</language>
    <item>
      <title>Bookplorer</title>
      <dc:creator>Sunny Praksah</dc:creator>
      <pubDate>Sun, 03 Jan 2021 18:19:06 +0000</pubDate>
      <link>https://dev.to/sprakash57/bookplorer-55ld</link>
      <guid>https://dev.to/sprakash57/bookplorer-55ld</guid>
      <description>&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;I have built &lt;strong&gt;Bookplorer&lt;/strong&gt; app, a dedicated book finder. I have used Svelte ecosystem and neumorphic style. It is deployed using DigitialOcean's App platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  Category Submission:
&lt;/h3&gt;

&lt;p&gt;I would say this falls into the "Program for the people" category. The reason is pretty much clear, It will help users to find books.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Link
&lt;/h3&gt;

&lt;p&gt;Since the app itself has been deployed to DigitalOcean, live demo can be found over &lt;a href="https://bookplorer-mn5g9.ondigitalocean.app/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Screenshots
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L2oomDrs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mgmmuh2xext1qvs8wjra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L2oomDrs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mgmmuh2xext1qvs8wjra.png" alt="Landing page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NXaIK9NC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7s805jbi4h5xt5028hzb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NXaIK9NC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7s805jbi4h5xt5028hzb.png" alt="Search results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HuzdVfyx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w5fa34urvlnc2gzjku1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HuzdVfyx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w5fa34urvlnc2gzjku1w.png" alt="Sidebar"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Description
&lt;/h3&gt;

&lt;p&gt;Bookplorer is all about finding your favorite books, share them with your friends on social media or you can buy them. It is backed by Google Books API. You can explore books with the help of volume or Author name. Decorated with &lt;strong&gt;neumorphic&lt;/strong&gt; style, this app comes with a lean and clean UI.&lt;/p&gt;

&lt;h3&gt;
  
  
  Link to Source Code
&lt;/h3&gt;

&lt;p&gt;Github repo link: &lt;a href="https://github.com/sprakash57/Bookplorer"&gt;https://github.com/sprakash57/Bookplorer&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Permissive License
&lt;/h3&gt;

&lt;p&gt;Bookplorer is licensed under the MIT license.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;Of course, you can google anything and everything. But sometimes results become cluttered with other non-wanted articles and materials. Bookplorer has one goal, that your search results should reflect books by removing other distracting stuff. &lt;/p&gt;

&lt;p&gt;In this pandemic, I felt that people should have utilized most of their time by reading books. Books, they thought that they will read someday. This utility will help you search those books, share them with your friends, or buy them.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I built it
&lt;/h3&gt;

&lt;p&gt;Bookplorer is built using Svelte ecosystem. Yes!! I ditched Vue and React. Why? Because I really wanted to learn this awesome framework by building something. Well, what's better than a hackathon. The icing on the cake was DigitalOcean's app platform that made the deployment process "A Child's play". Most importantly the &lt;strong&gt;Autodeploy code changes&lt;/strong&gt; feature.&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Resources/Info
&lt;/h3&gt;

&lt;p&gt;It was not possible to build the app without &lt;a href="https://developers.google.com/books/docs/v1/using#st_params"&gt;Google Books API&lt;/a&gt; and &lt;a href="https://svelte.dev/tutorial/basics"&gt;Svelte tutorial&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  That's about it
&lt;/h1&gt;

&lt;p&gt;Do checkout my other blogs &lt;a href="https://suprdev.netlify.app/blog/"&gt;here&lt;/a&gt;. Follow me on Twitter @sunny_pr_ to get updates on the latest blog. Thanks for reading!!&lt;/p&gt;

</description>
      <category>dohackathon</category>
      <category>svelte</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Beyond console.log()</title>
      <dc:creator>Sunny Praksah</dc:creator>
      <pubDate>Mon, 02 Nov 2020 06:49:59 +0000</pubDate>
      <link>https://dev.to/sprakash57/beyond-console-log-bgo</link>
      <guid>https://dev.to/sprakash57/beyond-console-log-bgo</guid>
      <description>&lt;p&gt;When it comes to debugging JavaScript application, there could be multiple ways such as using browser's devtool or use of the debugger keyword in your code. But the most popular technique is to put console.log() inside your code. I know most of us will complain against the practice of using logs directly in your code. But honestly, everyone does that. You can not deny the fact 😁. What if I tell there are more ways of using &lt;strong&gt;Conosle API&lt;/strong&gt; and its method that you probably wouldn't think of. It will definitely enhance your logging experience. So without further ado, let's do further&lt;/p&gt;

&lt;h2&gt;
  
  
  console.log()
&lt;/h2&gt;

&lt;p&gt;The most common method of all time. But I won't talk about the boring stuff that you might know already. There are some nifty features that will stand out in your logs in devtool. Like formatting the text with CSS styling and outputting c-like strings. Let's take an example -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str = "'Sunny Prakash'"
console.log("Hi! I am %s", str)
// Hi! I am 'Sunny Prakash'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can even go one step further and create your own styled logger function and use it instead of plain old console.log(). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl88jvaoca0p6190yvvrv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl88jvaoca0p6190yvvrv.png" alt="log"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are wondering what CSS property you can use, I have jotted them down for you.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;background&lt;/li&gt;
&lt;li&gt;border&lt;/li&gt;
&lt;li&gt;border-radius&lt;/li&gt;
&lt;li&gt;box-shadow&lt;/li&gt;
&lt;li&gt;clear and float&lt;/li&gt;
&lt;li&gt;color&lt;/li&gt;
&lt;li&gt;cursor&lt;/li&gt;
&lt;li&gt;display&lt;/li&gt;
&lt;li&gt;font-related properties&lt;/li&gt;
&lt;li&gt;line-height&lt;/li&gt;
&lt;li&gt;margin&lt;/li&gt;
&lt;li&gt;outline&lt;/li&gt;
&lt;li&gt;padding&lt;/li&gt;
&lt;li&gt;text-* properties such as text-transform&lt;/li&gt;
&lt;li&gt;white-space&lt;/li&gt;
&lt;li&gt;word-spacing&lt;/li&gt;
&lt;li&gt;word-break&lt;/li&gt;
&lt;li&gt;writing-mode&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  console.dir()
&lt;/h2&gt;

&lt;p&gt;Have you ever used console.log() to print HTML elements as object just to verify properties like value, target, style, classes, and innerHTML, etc but you failed miserably? Because all it would print is -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button&amp;gt;Simple button&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not enough intel, right?! Well, console.dir() solves this problem and opens up that HTML element. It will log them as objects so you can explore every property of it without any hassle.&lt;/p&gt;

&lt;h2&gt;
  
  
  console.info(), .warn() and .error()
&lt;/h2&gt;

&lt;p&gt;If you are 100% sure that whatever you are logging is info/error/warn then instead of using console.log(), go for these options. Why? Because you can create your own warning/error messages in certain scenarios, that doesn't come with javaScript naturally. It might help a fellow developer to stick to guidelines while developing any story or fixing any bug. Messages will appear in a different format and color that makes them easy to detect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.info("Write clean code");
console.warn("Warning!! you better don't think of doing it");
console.error("You just did, and you got the error afterward");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oh! and did I mention, that you can still apply text formatting and all other good stuff which we learned in console.log()&lt;/p&gt;

&lt;h2&gt;
  
  
  console.group([label]) and groupEnd()
&lt;/h2&gt;

&lt;p&gt;As the name suggests you can group together a certain number of consoles together. For example, let's say you put consoles inside a method at several places and you are repeating the same thing with another function as well. To make those logs visually distinctive what you can do is to put strings such as &lt;code&gt;console.log('func1', ...)&lt;/code&gt; and &lt;code&gt;console.log('func2', ...)&lt;/code&gt;. But why make logs more verbose when you actually group them together there, wouldn't that be great? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxhran277isbb3llqz1qh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxhran277isbb3llqz1qh.png" alt="group"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;console.group([label]) takes an optional parameter called label that acts as a group name. If you don't provide label the default value would the function name. You can nest a group inside a group as well. grouping will be closed if you call &lt;code&gt;groupEnd()&lt;/code&gt; method at the last.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.group("Group A")
console.log('something')
console.group("Nested inside A")
console.log('something again')
console.groupEnd()
console.groupEnd()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  console.assert(assertion, [object, string] )
&lt;/h2&gt;

&lt;p&gt;If you have ever written unit test cases then you must be knowing what assertion is. If you don't, well let me brief. Assertion means testing a functionality against a certain scenario. You simply assert a condition and check the output whether it is expected or not. If that is the case then the test case passes otherwise it fails. Console API provides you a way to log errors only if some assertion fails. Eg:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i=0;i&amp;lt;=5;i++){
    console.log("checking %d...", i);
    console.assert(i%2===0, "%d is not divisible by 2", i)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  console.table([object, array])
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;console.table()&lt;/code&gt; takes either an object or an array and displays them in tabular format. You heard it right "in a table" without any extra line of code. You won't believe how easy it is to read them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Foq0f5ttuwrsgrv8c2uuc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Foq0f5ttuwrsgrv8c2uuc.png" alt="table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to display only a few columns, well you can do that as well -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.table([fooBar, jhonDoe], ["name"])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  console.trace([...any, ...data])
&lt;/h2&gt;

&lt;p&gt;This method prints a stack trace to the Web console. It's a miniature version of the browser's call stack that will appear in the console tab on the fly. So now you can check the call stack without even using debug tools 😆.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi7oh875b0l02knqhzjf9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi7oh875b0l02knqhzjf9.png" alt="trace"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And with this, we come to wrap this session. I hope you have found this article of some use. Let me know in case I have missed something in the comments or you can visit my &lt;a href="https://suprdev.netlify.app/contact" rel="noopener noreferrer"&gt;website&lt;/a&gt; to provide your valuable feedback.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>debugging</category>
    </item>
    <item>
      <title>Let's talk about ES2020</title>
      <dc:creator>Sunny Praksah</dc:creator>
      <pubDate>Sun, 25 Oct 2020 06:22:07 +0000</pubDate>
      <link>https://dev.to/sprakash57/let-s-talk-about-es2020-5369</link>
      <guid>https://dev.to/sprakash57/let-s-talk-about-es2020-5369</guid>
      <description>&lt;p&gt;As 2020 is about to complete its tenure, most of us do not want to remember this year at all. But good things happened as well. One of them is ES2020, which we will discuss in this post. &lt;/p&gt;

&lt;p&gt;ES2020 A.K.A ES11 is the latest set of standards included in EcmaScript. A little background of EcmaScript, they are those who decide the standard way of writing JavaScript code, such that the interoperability of Web pages across different Web browsers must remain intact.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why are we going through this?
&lt;/h3&gt;

&lt;p&gt;Day by day different projects are opting for ES6+ standards globally. To keep up with the pace, the sooner you will start adopting new features, the better. New features tending more towards TypeScript like features (but without types). Also, it is less confusing, more straight-forward, and feels like other Object-oriented Programming languages.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;P.S:- Since this post is quite long. I don't want you to sleep or get rid of it. You can access this GitHub gist &lt;a href="https://gist.github.com/sprakash57/124ee72f2c8a3a38b7bf65ba68918860"&gt;here&lt;/a&gt; and have a quick look around.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's proceed, shall we?&lt;/p&gt;

&lt;h2&gt;
  
  
  1. BigInt
&lt;/h2&gt;

&lt;p&gt;If I ask, what is the largest number in JavaScript? The Answer should be 2&lt;sup&gt;53&lt;/sup&gt; - 1. What if you want to represent numbers more than that figure? You have &lt;code&gt;BigInt&lt;/code&gt;. A BigInt is a number appended by suffix &lt;code&gt;n&lt;/code&gt;. For example &lt;code&gt;223n&lt;/code&gt; is a BigInt. What is this? Looks like a string. But it's not. You see, when you will try to execute &lt;code&gt;typeof 223n&lt;/code&gt; it will give you &lt;code&gt;bigint&lt;/code&gt;. Boom!!! A new type in JavaScript. So in your next interview, If someone asks what are the types in JS, you know what to tell them first. You welcome!!&lt;/p&gt;

&lt;p&gt;Since we are talking about JavaScript, strange things are eminent.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;"1" + 10n&lt;/code&gt; will give "11". But &lt;code&gt;1 + 10n&lt;/code&gt; will throw an error stating "you can not mix bigint and other types". However, you can compare Number and BigInt with the breeze. More examples are &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;BigInts are loosely equal to Number.&lt;/li&gt;
&lt;li&gt;It can not be used with methods built in Math Object.&lt;/li&gt;
&lt;li&gt;You can use toString() method, that will return string representation of bigint minus &lt;code&gt;n&lt;/code&gt; suffix. So &lt;code&gt;112n.toString()&lt;/code&gt; will result in "112".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One use case, I can think of is in Problem Solving, where you will be given a long integer and you will be told to do some operation on it. the most tempting way would be to convert it to string and proceed. But now you know the other way as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Promise.allSettled()
&lt;/h2&gt;

&lt;p&gt;You have used Promise.all and you must have thought, why there isn't a way to get the result irrespective of promise status. Well my friend, you are in luck. Because Promise has this new API that will give you all settled(resolved/rejected) every single time. It will return an array of resolved or rejected objects &lt;code&gt;{status: "fulfilled", value: "Just arrived"}&lt;/code&gt; or &lt;code&gt;{status: "rejected", reason: "Some popular error"}&lt;/code&gt;. Let's look at the example -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Promise.allSettled([
    new Promise(res =&amp;gt; setTimeout(() =&amp;gt; res(1), 3000)),
    new Promise((res, rej) =&amp;gt; setTimeout(() =&amp;gt; rej(new Error("Oops")), 5000)),
    new Promise(res =&amp;gt; setTimeout(() =&amp;gt; resolve(3), 1000))
]).then(data =&amp;gt; console.log(data));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  { status: 'fulfilled', value: 1 },
  { status: 'rejected', reason: Error: oops...},
  { status: 'fulfilled', value: 3 }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Promise.all([
    new Promise(res =&amp;gt; setTimeout(() =&amp;gt; res(1), 3000)),
    new Promise((res, rej) =&amp;gt; setTimeout(() =&amp;gt; rej(new Error("Oops")), 5000)),
    new Promise(res =&amp;gt; setTimeout(() =&amp;gt; resolve(3), 1000))
]).then(data =&amp;gt; console.log(data)); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UnhandledPromiseRejectionWarning: Error: Oops
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Nullish Coalescing (??)
&lt;/h2&gt;

&lt;p&gt;If you have ever used TypeScript, you must have come across this operator. It's more like an inbuilt undefined safety feature. Previously we had &lt;code&gt;||&lt;/code&gt; to fallback if the first operand results in falsy. &lt;code&gt;??&lt;/code&gt; is different. It will strictly check whether the first operand is &lt;code&gt;undefined&lt;/code&gt; or not. For example -&lt;/p&gt;

&lt;p&gt;console.log(undefined || "1"); // "1"&lt;br&gt;
console.log(undefined ?? "1"); // "1"&lt;br&gt;
console.log(0 || "1"); // "1"&lt;br&gt;
console.log(0 ?? "1"); // 0&lt;/p&gt;

&lt;p&gt;Just remember this - undefined is always falsy, but not all falsies are undefined.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Optional chaining (?)
&lt;/h2&gt;

&lt;p&gt;This again hails from the world of TypeScript. If you are fetching some multi-level nested JSON object, and want to access any deep properties inside that JSON, two things might happen. Either you will get it or not. That might break your application due to the infamous "Reference Error". Let's take an example -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const response = {
    first: {
        second: { 
            fourth: "this you want to access"
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What will happen if I access "third", which is not there?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(first.third.fourth); //Reference error for third
console.log(first?.third?.fourth); //undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. globalThis
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; was a nightmare for all JS veterans already, what's up with globalThis. Well, it has nothing to do with &lt;code&gt;this&lt;/code&gt;, not directly. You see, the global object in javaScript was not standardized. You have &lt;code&gt;window&lt;/code&gt; in browsers, &lt;code&gt;global&lt;/code&gt; in node.js, and &lt;code&gt;self&lt;/code&gt; in web workers. Imagine your production code has all of these components, how could you count on your global "this" without writing messy checks in all places. With ES2020, there are less confusion and more standards. You can use &lt;code&gt;globalThis&lt;/code&gt;, that's all!! No need to worry about the environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Dynamic Imports
&lt;/h2&gt;

&lt;p&gt;In the new ES2020 you can use dynamic imports. How? imports are no longer bound to be imported first and use later. Now you can import your methods, object, etc dynamically. It will return a promise that you need to handle.&lt;/p&gt;

&lt;p&gt;print.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const print = (value) =&amp;gt; `Hi ${value}`

export { print };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;greet.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const greet = value =&amp;gt; import('./print.js).then(func =&amp;gt; func(value));
greet("sunny"); //Hi sunny
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. String.prototype.matchAll()
&lt;/h2&gt;

&lt;p&gt;Unlike &lt;code&gt;match()&lt;/code&gt; it will return an iterator. The results can also be achieved with &lt;code&gt;regexp.exec()&lt;/code&gt; however below example will show you how the number of lines can reduce drastically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const regexp = RegExp('[a-z]*ame','g');
const str = 'rame suot name vjaoi game';
let match;
while ((match = regexp.exec(str)) !== null) {
  console.log(match)
}
// Same as
console.log(...str.matchAll(regexp));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>es2020</category>
    </item>
    <item>
      <title>Integrate express-validator to your express API</title>
      <dc:creator>Sunny Praksah</dc:creator>
      <pubDate>Tue, 29 Sep 2020 14:47:23 +0000</pubDate>
      <link>https://dev.to/sprakash57/integrate-express-validator-to-your-express-api-2dg6</link>
      <guid>https://dev.to/sprakash57/integrate-express-validator-to-your-express-api-2dg6</guid>
      <description>&lt;h4&gt;
  
  
  The original post can be found over &lt;a href="https://suprdev.netlify.com/blog/express-validator"&gt;here&lt;/a&gt;.
&lt;/h4&gt;

&lt;h2&gt;
  
  
  Why do I need express-validator?
&lt;/h2&gt;

&lt;p&gt;Short and simple if your UI is using forms or multiple input fields and in the backend express application you want to validate those data against database schema, then you need to validate them first before you actually process it. Sure, you can do all the validation manually by writing all sorts of logics and regexes. But why reinvent the wheel if something is doing that for you already. This is where the express-validator library comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  I hate too much dependent libraries. what about it?
&lt;/h2&gt;

&lt;p&gt;express-validator is a wrapper around validator.js and uses lodash for its data manipulation, that's it. So basically you have two dependencies. I am sure you must have using lodash already, so no extra packages and libraries to take care of.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ok genius, but I can write my own middleware to achieve it? how this library of yours better than that?
&lt;/h2&gt;

&lt;p&gt;Man, you are a tough nut to crack. Of course, you can do everything in this world by yourselfff. But think about how easy it will be to validate your express routes. You can do that out of the box by using express-validator in your express application. Ohh and Did I mention you can also sanitize your data? Plus you have all the freedom to customize your error messages. Keep reading and I will show you how.&lt;/p&gt;

&lt;p&gt;To explain things I will be taking reference from one of my Github repo &lt;a href="https://github.com/sprakash57/Contrivocial"&gt;https://github.com/sprakash57/Contrivocial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Prerequisite&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;node.js v6+&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Installation&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npm i -S express-validator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;P.S: &lt;em&gt;At the time I am writing this blog, express-validator has version 6.6.1. It may not be the same for you.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1 - middleware/validation.js (Just to keep every validation at a single place).
&lt;/h3&gt;

&lt;p&gt;Here I am taking an example of user registration with 3 fields namely name, email, &amp;amp; password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { check } = require('express-validator');

exports.signupValidation = [
    check('name', 'Name is requied').not().isEmpty(),
    check('email', 'Please include a valid email').isEmail().normalizeEmail({ gmail_remove_dots: true }),
    check('password', 'Password must be 6 or more characters').isLength({ min: 6 })
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need to import &lt;code&gt;check&lt;/code&gt; first. It takes two parameters. The first one is the field and the second is the error message that you want to send in the response.&lt;/p&gt;

&lt;p&gt;You can chain methods on the &lt;code&gt;check&lt;/code&gt; to carry out the validations like isEmail or isEmpty. Want some sanitization, you can append sanitization methods as well. A Useful list can be found over here. My favorite is normalizeEmail({ gmail_remove_dots: true }). It will treat &lt;a href="mailto:sunnyprakash@gmail.com"&gt;sunnyprakash@gmail.com&lt;/a&gt; and &lt;a href="mailto:sunny.prakash@gmail.com"&gt;sunny.prakash@gmail.com&lt;/a&gt; as equal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { signupValidation } = require('../../middleware/validation');

router.post('/register', signupValidation, userController.register);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second step is all about tweaking your routes. Inside the user registration route, I have introduced signupValidation middleware that was created in step 1.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 - controllers/user.js
&lt;/h3&gt;

&lt;p&gt;Now Its time to change our user registration controller a little bit. To catch all the validation messages inside this controller I have imported validationResult from express-validator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { validationResult } = require('express-validator');

exports.register = async (req, res) =&amp;gt; {

  const errors = validationResult(req);

  if (!errors.isEmpty()) return res.status(400).json({ errors: errors.array() });

  ......

  ......

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

&lt;/div&gt;



&lt;p&gt;To get the messages out of the signupValidation method present inside validation.js, you need to pass the request object to it. Once that is done, you can access all error messages in an array format by using errors.array().&lt;/p&gt;

&lt;p&gt;And that's all folks, you don't need to touch your app.js. I have just scratched the surface. There is a lot you can achieve. But I think This would be sufficient for a beginner getting started with express. To dig in more you can read their official doc &lt;a href="https://express-validator.github.io/docs"&gt;https://express-validator.github.io/docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Check out the complete implementation of the above in my Github repo over &lt;a href="https://github.com/sprakash57/Contrivocial"&gt;here&lt;/a&gt;. See if it helps to set things up for you. A star to the repo would be highly appreciated.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>5 less common array methods in JavaScript</title>
      <dc:creator>Sunny Praksah</dc:creator>
      <pubDate>Mon, 25 May 2020 03:30:53 +0000</pubDate>
      <link>https://dev.to/sprakash57/5-less-common-array-methods-in-javascript-43c1</link>
      <guid>https://dev.to/sprakash57/5-less-common-array-methods-in-javascript-43c1</guid>
      <description>&lt;p&gt;The title "Less common" holds since I haven't seen them getting used very frequently. Because there are popular data structure libraries (lodash, underscore, etc) present out there to do the heavy lifting. I won't be talking about those methods. Let's cover what vanilla JavaScript has to offer -&lt;/p&gt;

&lt;h2&gt;
  
  
  copyWithin(target[, start[, end]])
&lt;/h2&gt;

&lt;p&gt;As the name suggests it copies part of an array to other locations in the same array. Here copying process is shallow, which mutates the original array. It takes three parameters. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;target - Index at which copy the sequence to. The negative index will be counted from the end. If the target is equal or greater than arr.length then nothing will be copied&lt;/li&gt;
&lt;li&gt;start - Index at which to start copying elements from. The same negative indexing concept applies here as well. If omitted then copying will start from index 0.&lt;/li&gt;
&lt;li&gt;end - Same usage as start. The only difference is copyWithin() does not include this index.
Lets take an example to understand them -
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = ['john', 'doe', 'foo', 'bar', 'egg'];
console.log(arr.copyWithin(0,1,3)); //Answer - ["doe", "foo", "foo", "bar", "egg"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  flatMap(function callback(currentValue[, index[, array]])
&lt;/h2&gt;

&lt;p&gt;It maps every element of an array using the callback function and returns a new flatten array. So basically its a fusion between flat and map methods (like Goku + Vegita = Gogita 😁 - DBZ fans). Lets observe its super powers -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr = ["Hi I am", "", "Sunny Prakash"];
console.log(arr.flatMap(x =&amp;gt; x.split(" ")));
//[ 'Hi', 'I', 'am', '', 'Sunny', 'Prakash' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tokenization achieved!! Pretty cool right.&lt;/p&gt;

&lt;h2&gt;
  
  
  every(callback(element[, index[, array]])[, thisArg])
&lt;/h2&gt;

&lt;p&gt;Let say you have an array of objects. And you want to return true/false based on some condition that has been satisfied by every object present in the array. Huh!! what's the big deal you can achieve it with find. In a way yes, you can. But I mentioned you should specifically return booleans. &lt;em&gt;every&lt;/em&gt; should be your first weapon in your arsenal to tackle this situation. &lt;em&gt;every&lt;/em&gt; takes two parameters. First is the callback and the second can be used as 'this' for the callback. The callback itself takes three parameters namely array element, index of the element, and the array itself. For example -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isBelowTotal(current, i, originalArray){
return current &amp;lt; this.total * this.tax
}
const arr = [1, 30, 39, 29, 10, 130];
console.log(arr.every(isBelowTotal, {tax: 0.4, total: 100}));
// false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  some(callback(element[, index[, array]])[, thisArg])
&lt;/h2&gt;

&lt;p&gt;some is same as every method. Except one condition but most important one. It tests whether at least one element in the array passes the condition implemented in the callback. So if every works like an &amp;amp;&amp;amp; operator then some works like || operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const employee = [
{name: 'sunny', gender: 'male'},
{name: 'Rakesh', gender: 'male'},
{name: 'Indrani', gender: 'female'}
]
cons hasFemaleEmployee = employee(emp =&amp;gt; emp.gender === 'female');
//hasFemaleEmployee = true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  slice([begin[, end]])
&lt;/h2&gt;

&lt;p&gt;I won't say it is used rarely, but people often get confused between slice and splice. So I have included in my list. slice takes two indices of which the second one is excluded and it will return a new array containing a sliced portion of the original array. Note here that the original array will not be mutated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const alpha = ['A', 'B', 'C', 'D', 'E'];
const sliced = alpha.slice(2);
console.log(sliced); // ['C', 'D', 'E']
console.log(alpha); // ['A', 'B', 'C', 'D', 'E']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;splice, on the other hand, changes the content of the original array by replacing or removing elements. Its first parameter is the start index and the second is deleteCount. However, there is a third parameter that exists as well which distinguishes whether splice will remove or replace elements. splice also returns the removed element, but it will modify the original array as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const alpha = ['A', 'B', 'C', 'D', 'E'];
const spliced = alpha.splice(0,1);
console.log(spliced); // ['A']
console.log(alpha); // ['B', 'C', 'D', 'E']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For further reading, you can refer to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"&gt;MDN Docs&lt;/a&gt;. You can find the original post &lt;a href="https://suprdev.netlify.app/blog/array-methods"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let me know your feedbacks in the comment.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>array</category>
    </item>
    <item>
      <title>Add Eat Repeat</title>
      <dc:creator>Sunny Praksah</dc:creator>
      <pubDate>Sat, 18 Apr 2020 14:05:30 +0000</pubDate>
      <link>https://dev.to/sprakash57/add-eat-repeat-4lgn</link>
      <guid>https://dev.to/sprakash57/add-eat-repeat-4lgn</guid>
      <description>&lt;p&gt;This lockdown has given us opportunity to invest time in ourselves, explore, learn and create things. Well this app is on of those good things. Take a look here&lt;br&gt;
&lt;a href="https://play.google.com/store/apps/details?id=com.insu.sunny.addeatrepeat"&gt;https://play.google.com/store/apps/details?id=com.insu.sunny.addeatrepeat&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last time i created an app with react-native-cli. Apart from code writing i had to take care of several other things. Well this time things changed. I tried my hands on Expo and its managed work flow. I was pretty impressed the way Expo hold your hands from development environment till app store bundle generation with via their extensive doc. Only downside was the size of the app.&lt;/p&gt;

&lt;p&gt;Do you think Expo is worth exploring? Would you prefer it over vanilla react-native-cli?&lt;/p&gt;

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