<?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: Santan Sharma</title>
    <description>The latest articles on DEV Community by Santan Sharma (@santansharma).</description>
    <link>https://dev.to/santansharma</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%2F617037%2Fdb2a6343-a26b-4f9a-b1f0-4426754946f9.png</url>
      <title>DEV Community: Santan Sharma</title>
      <link>https://dev.to/santansharma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/santansharma"/>
    <language>en</language>
    <item>
      <title>Why Most Developers Get Bad AI Output (And How I Fixed It in VS Code)</title>
      <dc:creator>Santan Sharma</dc:creator>
      <pubDate>Sun, 18 Jan 2026 00:12:47 +0000</pubDate>
      <link>https://dev.to/santansharma/why-most-developers-get-bad-ai-output-and-how-i-fixed-it-in-vs-code-4i2i</link>
      <guid>https://dev.to/santansharma/why-most-developers-get-bad-ai-output-and-how-i-fixed-it-in-vs-code-4i2i</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;AI tools like ChatGPT and Claude are incredibly powerful — yet many developers still get disappointing results.&lt;/p&gt;

&lt;p&gt;The problem isn’t the model.&lt;br&gt;&lt;br&gt;
It’s the prompt.&lt;/p&gt;

&lt;p&gt;Unclear, rushed, and poorly structured prompts force the AI to guess, which leads to vague or incorrect output. After running into this problem repeatedly in my own workflow, I built &lt;strong&gt;PromptLint&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Real Problem: Bad Prompts
&lt;/h2&gt;

&lt;p&gt;Most prompts look like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There’s no context.
&lt;/li&gt;
&lt;li&gt;No constraints.
&lt;/li&gt;
&lt;li&gt;No clear expectations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The AI has to fill in the gaps — and guessing is exactly why the output falls apart.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Solution: PromptLint
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;PromptLint&lt;/strong&gt; is a VS Code extension that refactors rough prompts into clear, structured, professional instructions.&lt;/p&gt;

&lt;p&gt;It automatically introduces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear roles
&lt;/li&gt;
&lt;li&gt;Explicit tasks
&lt;/li&gt;
&lt;li&gt;Defined requirements
&lt;/li&gt;
&lt;li&gt;Constraints and edge cases
&lt;/li&gt;
&lt;li&gt;Expected output format
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result is dramatically better AI responses — &lt;strong&gt;without switching models or tools&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;PromptLint integrates directly into VS Code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Refactor selected text via right-click
&lt;/li&gt;
&lt;li&gt;Use the interactive Prompt Editor panel
&lt;/li&gt;
&lt;li&gt;Choose output options:

&lt;ul&gt;
&lt;li&gt;Replace selection
&lt;/li&gt;
&lt;li&gt;Open in a new tab
&lt;/li&gt;
&lt;li&gt;Copy to clipboard
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Works with OpenAI, Claude, and other compatible APIs
&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;No workflow disruption.&lt;br&gt;&lt;br&gt;
No extra tools to learn.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Before
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;write code for login&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  After
&lt;/h3&gt;

&lt;p&gt;A fully structured prompt with a defined role, clear requirements, constraints, and output expectations — producing significantly better results.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Same AI. Better input. Better output.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Who Should Use PromptLint
&lt;/h2&gt;

&lt;p&gt;PromptLint is built for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Developers who use ChatGPT or Claude daily
&lt;/li&gt;
&lt;li&gt;Engineers writing technical or system-level prompts
&lt;/li&gt;
&lt;li&gt;Anyone tired of re-prompting AI to “fix” bad answers
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you use AI seriously, &lt;strong&gt;prompt quality is not optional&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;AI isn’t replacing developers.&lt;br&gt;&lt;br&gt;
Developers who use AI &lt;strong&gt;effectively&lt;/strong&gt; will replace those who don’t.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PromptLint exists to make that advantage automatic.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>vscode</category>
      <category>ai</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Understanding JavaScript Closures — The Secret Behind the Magic</title>
      <dc:creator>Santan Sharma</dc:creator>
      <pubDate>Sat, 26 Jul 2025 21:58:48 +0000</pubDate>
      <link>https://dev.to/santansharma/understanding-javascript-closures-the-secret-behind-the-magic-4m08</link>
      <guid>https://dev.to/santansharma/understanding-javascript-closures-the-secret-behind-the-magic-4m08</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is a Closure?&lt;/strong&gt;&lt;br&gt;
A closure is when a function "remembers" the variables from the place where it was created — even after that place is gone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In simpler terms:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A closure gives you access to an outer function’s scope from an inner function.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Why Should You Care?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Closures are everywhere in JavaScript:&lt;/li&gt;
&lt;li&gt;They power callbacks and event handlers&lt;/li&gt;
&lt;li&gt;They're behind the scenes in setTimeout, promises, and Angular zones&lt;/li&gt;
&lt;li&gt;They help you encapsulate data (like in OOP)&lt;/li&gt;
&lt;li&gt;They make function factories and private variables possible&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Let’s Break It Down with a Real-Life Analogy&lt;/strong&gt;&lt;br&gt;
Imagine your local tea vendor (chaiwala) 🫖. You go there every day. You give your name and he remembers your order. Even after 3 days, he says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Bhaiya, adrak wali chai na? Theek hai.”_&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How did he remember? Did you write it down? No.&lt;br&gt;
He closed over your name and chai preference. That's how closures work. 😄&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function makeTea(type) {
  return function () {
    console.log(`Here is your ${type} tea ☕`);
  };
}

const gingerTea = makeTea("Ginger");
const greenTea = makeTea("Green");

gingerTea();  // Here is your Ginger tea ☕
greenTea();   // Here is your Green tea ☕
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧠 &lt;strong&gt;What's happening here?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;makeTea("Ginger") returns a new function&lt;br&gt;
That function remembers type = "Ginger" even after makeTea has finished running&lt;br&gt;
That memory is the closure&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real Use Case: Button Click in Angular or Vanilla JS&lt;/strong&gt;&lt;br&gt;
Let’s say you're making a dashboard where clicking a button shows different messages. You want each button to "remember" its own message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function setupButton(id, message) {
  document.getElementById(id).addEventListener('click', function () {
    alert(message);
  });
}

setupButton("btn1", "Dashboard loaded!");
setupButton("btn2", "Settings loaded!");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each button now has its own closure. Without closures, all buttons would alert the same last message.&lt;/p&gt;

&lt;p&gt;🧙 &lt;strong&gt;Fun Fact: Closures Make Data Private&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can use closures to simulate private variables just like in OOP.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Counter() {
  let count = 0;
  return {
    increment: function () {
      count++;
      return count;
    },
    decrement: function () {
      count--;
      return count;
    }
  };
}

const counter = Counter();
console.log(counter.increment()); // 1
console.log(counter.decrement()); // 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;count&lt;/strong&gt; is not accessible directly — only via the functions. A neat encapsulation trick!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where People Get Confused&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Does a closure copy the variable?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No, it remembers the reference to the variable.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Can it keep many variables?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Yes, any variables in its scope at creation are remembered.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Will it cause memory leaks?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Not usually. Modern engines manage it well unless you accidentally create long-lived references (like in DOM events).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;** &amp;gt; Closures may sound intimidating, but they are a natural part of JavaScript — especially functional programming and frontend frameworks like Angular.**&lt;/p&gt;

&lt;p&gt;&lt;code&gt;If you understand closures, you understand how JavaScript thinks.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So next time someone talks about JavaScript being weird, just smile and say:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;“It’s not weird. It’s just... closed over logic.”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;🙌 &lt;strong&gt;Final Thought&lt;/strong&gt;&lt;br&gt;
If you liked this explanation and want more on things like async/await, this keyword, or Angular Observables in plain English — let me know! We can break the toughest nuts together 🧠🔧&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>What is event bubbling and event capturing in JavaScript?</title>
      <dc:creator>Santan Sharma</dc:creator>
      <pubDate>Sun, 12 Mar 2023 10:26:36 +0000</pubDate>
      <link>https://dev.to/santansharma/what-is-event-bubbling-and-event-capturing-in-javascript-g18</link>
      <guid>https://dev.to/santansharma/what-is-event-bubbling-and-event-capturing-in-javascript-g18</guid>
      <description>&lt;p&gt;Imagine you're at a party with a group of friends. You're all hanging out in the living room, but suddenly someone yells "PIZZA IS HERE!" and everyone starts rushing towards the door.&lt;/p&gt;

&lt;p&gt;Event capturing is like your friend who heard the pizza guy outside and ran out to meet him at the front gate. He's trying to intercept the pizza before it even gets to the door, so he can get the first slice.&lt;/p&gt;

&lt;p&gt;Event bubbling, on the other hand, is like when the pizza finally makes it to the door, and everyone in the living room rushes towards the door to get their slice. It starts with the person closest to the door, and then moves outward to include everyone else in the room.&lt;/p&gt;

&lt;p&gt;In JavaScript, events work in a similar way. When something happens, like a button is clicked, the event starts at the top-level "document" element and then moves down to the specific element that was clicked. That's event capturing. Then, once the event has been handled by the clicked element, it starts "bubbling" back up to the top-level document element, passing through all the parent elements along the way.&lt;/p&gt;

&lt;p&gt;I hope that helps make event bubbling and event capturing a bit more fun and memorable!&lt;/p&gt;

&lt;p&gt;If you enjoyed this post, please consider following me for more content like this!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>what is an interface and abstract class in c# and its difference?</title>
      <dc:creator>Santan Sharma</dc:creator>
      <pubDate>Wed, 08 Feb 2023 06:44:26 +0000</pubDate>
      <link>https://dev.to/santansharma/what-is-an-interface-and-abstract-class-in-c-and-its-difference-2ad2</link>
      <guid>https://dev.to/santansharma/what-is-an-interface-and-abstract-class-in-c-and-its-difference-2ad2</guid>
      <description>&lt;p&gt;Think of an interface as a super strict boss who gives a list of tasks to his employees (classes) and expects them to complete all of those tasks perfectly.&lt;/p&gt;

&lt;p&gt;The boss (interface) only knows what needs to be done, but he has no idea how it should be done. So, he hands off the job description (a list of methods, properties, and events) to his employees (classes) and says "Get it done, I don't care how, just make sure you follow the instructions."&lt;/p&gt;

&lt;p&gt;And that's exactly what classes do! They take the job description from the boss (interface), and they come up with their own ways of completing the tasks. The boss is happy as long as all the tasks are completed, and the employees are happy because they get to use their own creativity to solve the problems.&lt;/p&gt;

&lt;p&gt;Now, let's talk about abstract classes. Imagine an abstract class as a boss who is a bit more involved in the process. He gives his employees (classes) a list of tasks to do, but also provides some guidance on how to do those tasks. He says "I have a general idea of how these tasks should be done, but feel free to use your own creativity and come up with your own solution."&lt;/p&gt;

&lt;p&gt;The key difference between an interface and an abstract class is that an interface only defines what needs to be done, whereas an abstract class provides both the what and the how.&lt;/p&gt;

&lt;p&gt;So, to summarize, an interface is like a boss who delegates tasks to his employees, but has no idea how they should be done. And classes are like employees who complete the tasks according to their own methods.&lt;/p&gt;

&lt;p&gt;In technological terms:-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INTERFACE&lt;/strong&gt;&lt;br&gt;
An interface in C# is a blueprint for a class. It defines a set of properties, methods, and events that must be implemented by any class that implements the interface. Interfaces provide a way to define a contract between a class and its clients. The clients can use this contract to interact with objects of the class without needing to know the underlying implementation.&lt;/p&gt;

&lt;p&gt;An interface contains only the signatures of methods, properties, and events, but not the implementation. The implementation of the members of an interface is provided by the classes that implement the interface.&lt;/p&gt;

&lt;p&gt;Interfaces are useful for creating loosely-coupled systems, as the implementation of an interface can be changed without affecting the code that depends on the interface. This makes it easier to maintain and evolve the system over time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface &amp;lt;interface_name&amp;gt; 
{
  // properties, methods, and events
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A class implements an interface using the "implements" keyword:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyClass : &amp;lt;interface_name&amp;gt;
{
  // implementation of properties, methods, and events
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ABSTRACT CLASS&lt;/strong&gt;&lt;br&gt;
An abstract class in C# is a class that cannot be instantiated on its own, but must be derived from by another class. An abstract class provides a base implementation of properties, methods, and events that can be shared by multiple derived classes.&lt;/p&gt;

&lt;p&gt;An abstract class can contain both abstract and non-abstract members (methods and properties). Abstract members are declared with the "abstract" keyword and do not have a body. The derived classes must implement these abstract members, providing their own implementation.&lt;/p&gt;

&lt;p&gt;Abstract classes are useful when you want to provide a common base implementation for multiple classes, but still allow for some variation in the implementation between the classes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class &amp;lt;abstract_class_name&amp;gt; 
{
  // abstract and non-abstract members
}

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

&lt;/div&gt;



&lt;p&gt;A class that derives from an abstract class uses the ":” operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyClass : &amp;lt;abstract_class_name&amp;gt;
{
  // implementation of abstract members and additional members
}

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

&lt;/div&gt;



&lt;p&gt;In conclusion, interfaces and abstract classes are important concepts in C# that provide a way to define contracts and create reusable code. Interfaces are used to define a set of methods and properties that a class must implement, while abstract classes provide a base implementation that can be shared by multiple derived classes.&lt;/p&gt;

&lt;p&gt;Choosing between an interface and an abstract class depends on the specific needs of your project and the relationships between the classes involved. Interfaces are best used when you want to define a contract for multiple classes to implement, whereas abstract classes are best used when you want to provide a common base implementation that can be shared by multiple derived classes.&lt;/p&gt;

&lt;p&gt;It's important to understand the differences between interfaces and abstract classes, as well as when and how to use them effectively, in order to write maintainable, scalable, and efficient code.&lt;/p&gt;

&lt;p&gt;Thanks for you time.&lt;br&gt;
have a good day.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>Learn how to use map, filter, and reduce in JavaScript.</title>
      <dc:creator>Santan Sharma</dc:creator>
      <pubDate>Wed, 24 Nov 2021 13:27:01 +0000</pubDate>
      <link>https://dev.to/santansharma/learn-how-to-use-map-filter-and-reduce-in-javascript-4ijp</link>
      <guid>https://dev.to/santansharma/learn-how-to-use-map-filter-and-reduce-in-javascript-4ijp</guid>
      <description>&lt;h1&gt;
  
  
  Higher Order Functions
&lt;/h1&gt;

&lt;p&gt;A higher-order function is a function that takes one or more functions as arguments or returns a function as its result. &lt;br&gt;
map, filter, and reduce are all higher order functions, which take a function as an argument.&lt;/p&gt;
&lt;h1&gt;
  
  
  Map, Filter, Reduce Fundamentals
&lt;/h1&gt;

&lt;p&gt;Map, reduce, and filter are all array methods in JavaScript. Each one will iterate over an array and perform a transformation or computation. Each will return a new array based on the result of the function.&lt;/p&gt;
&lt;h1&gt;
  
  
  .map()
&lt;/h1&gt;

&lt;p&gt;The map() method is used for creating a new array from an existing one, applying a function to each one of the elements of the first array.&lt;/p&gt;

&lt;p&gt;Every element of the array is passed to the callback function and returns a new array with the same length.&lt;br&gt;
When to use map: If we want to perform the same operation/transformation on each element of the array and get back a new array of the same length with the transformed values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var numbers= [1,2,3,4,5];
var doubled  = numbers.map(n =&amp;gt; n * 2);
doubled; // [2,4,6,8,10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  .filter()
&lt;/h1&gt;

&lt;p&gt;The filter() method takes each element in an array and it applies a conditional statement against it. If this conditional returns true, the element gets pushed to the output array. If the condition returns false, the element does not get pushed to the output array.&lt;/p&gt;

&lt;p&gt;Every element of the array is passed to the callback function. On each iteration, if the callback returns true, then that element will be added to the new array, otherwise, it is not added to the new array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var numbers = [1,2,3,4,5];
var greaterThan2 = numbers.filter(n =&amp;gt; n &amp;gt; 2);
greaterThan2; // [3,4,5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  .reduce()
&lt;/h1&gt;

&lt;p&gt;The reduce() method reduces an array of values down to just one value. To get the output value, it runs a reducer function on each element of the array.&lt;/p&gt;

&lt;p&gt;While using reduce, we need to declare the initial value of accumulator(final result). On each iteration, inside the callback we perform some operation and that will be added to the accumulator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var numbers = [1,2,3,4,5];
var initialVal = 0;
let result=numbers.reduce((accu, val) =&amp;gt; val + accu , initialVal);
console.log(result) // 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Real-world example
&lt;/h1&gt;

&lt;p&gt;Let’s create a real-world practical example: Conducting an Interview.&lt;/p&gt;

&lt;p&gt;1.map: Conducting a test for multiple candidates&lt;br&gt;
2.filter: Selecting candidates who passed the test&lt;br&gt;
3.reduce: Creating a team from the selected candidates&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var users = [{"user": "👩🏻‍💻"},{"user": "👨🏾‍💻"},{"user": "💃"},{"user": "👨🏻‍🎓"},{"user": "🧑🏻‍🏫"},{"user": "🦸‍♂️"},{"user": "🧟‍♂️"}];

let resultDetails = users.map(user =&amp;gt; {
    let mark = Math.random() * 100;
    user.mark = mark;
    return user
});
//for me resultDetails 
/*
0: {user: "👩🏻‍💻", mark: 76.03572182106969}
1: {user: "👨🏾‍💻", mark: 71.62190728557552}
2: {user: "💃", mark: 56.21776553271223}
3: {user: "👨🏻‍🎓", mark: 25.801390164601944}
4: {user: "🧑🏻‍🏫", mark: 85.74297532451267}
5: {user: "🦸‍♂️", mark: 67.11805101358996}
6: {user: "🧟‍♂️", mark: 18.253450044782184}
*/

var selectedCandidate = resultDetails.filter(user =&amp;gt; {
    if(user.mark &amp;gt; 50){
        return user;
    }
});
/* selected candidate 
0: {user: "👩🏻‍💻", mark: 76.03572182106969}
1: {user: "👨🏾‍💻", mark: 71.62190728557552}
2: {user: "💃", mark: 56.21776553271223}
3: {user: "🧑🏻‍🏫", mark: 85.74297532451267}
4: {user: "🦸‍♂️", mark: 67.11805101358996}
*/

// Create Team 

let TeamMembers = selectedCandidate.reduce((teamMembers,  user) =&amp;gt; {
     teamMembers.push(user);
    return teamMembers;
}, []);

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

&lt;/div&gt;



&lt;p&gt;KEEP IT SHORT AND SWEET!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Promise &amp; Async await in JavaScript.</title>
      <dc:creator>Santan Sharma</dc:creator>
      <pubDate>Wed, 29 Sep 2021 20:30:07 +0000</pubDate>
      <link>https://dev.to/santansharma/promise-async-await-in-javascript-mlb</link>
      <guid>https://dev.to/santansharma/promise-async-await-in-javascript-mlb</guid>
      <description>&lt;p&gt;&lt;strong&gt;Promise:&lt;/strong&gt;&lt;br&gt;
Imagine that you’re a top singer, and fans ask day and night for your upcoming song.&lt;/p&gt;

&lt;p&gt;To get some relief, you promise to send it to them when it’s published. You give your fans a list. They can fill in their email addresses, so that when the song becomes available, all subscribed parties instantly receive it. And even if something goes very wrong, say, a fire in the studio, so that you can’t publish the song, they will still be notified.&lt;/p&gt;

&lt;p&gt;This is a real-life analogy for things we often have in programming:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;“producing code” that does something and takes time. For instance, some code that loads the data over a network. That’s a “singer”.&lt;/li&gt;
&lt;li&gt;“consuming code” that wants the result of the “producing code” once it’s ready. Many functions may need that result. These are the “fans”.&lt;/li&gt;
&lt;li&gt;promise is a special JavaScript object that links the “producing code” and the “consuming code” together. In terms of our analogy: this is the “subscription list”. The “producing code” takes whatever time it needs to produce the promised result, and the “promise” makes that result available to all of the subscribed code when it’s ready.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Promises are a new feature of ES6. It’s a method to write asynchronous code. They are easy to manage when dealing with multiple asynchronous operations where callbacks can create callback hell leading to unmanageable code.&lt;/p&gt;
&lt;h6&gt;
  
  
  How It Works.
&lt;/h6&gt;

&lt;p&gt;There are 3 states of the Promise object:&lt;/p&gt;

&lt;p&gt;1.Pending: Initial State, before the Promise succeeds or fails&lt;br&gt;
2.Resolved: Completed Promise&lt;br&gt;
3.Rejected: Failed Promise&lt;/p&gt;
&lt;h6&gt;
  
  
  Creating and Using A Promise Step by Step
&lt;/h6&gt;

&lt;p&gt;Firstly, we use a constructor to create a Promise object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It takes two parameters, one for success (resolve) and one for fail (reject):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise((resolve, reject) =&amp;gt; {  
    // condition
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, there will be a condition. If the condition is met, the Promise will be resolved, otherwise it will be rejected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise((resolve, reject) =&amp;gt; {  
    let condition;  

    if(condition is met) {    
        resolve('Promise is resolved successfully.');  
    } else {    
        reject('Promise is rejected');  
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we have created our first Promise. Now let's use it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;then( ) for resolved Promises:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myPromise.then();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The then( ) method is called after the Promise is resolved. Then we can decide what to do with the resolved Promise.&lt;/p&gt;

&lt;p&gt;For example, let’s log the message to the console that we got from the Promise:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myPromise.then((message) =&amp;gt; {  
    console.log(message);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;catch( ) for rejected Promises:&lt;/strong&gt;&lt;br&gt;
However, the then( ) method is only for resolved Promises. What if the Promise fails? Then, we need to use the catch( ) method.&lt;/p&gt;

&lt;p&gt;Likewise we attach the then( ) method. We can also directly attach the catch( ) method right after then( ):&lt;/p&gt;

&lt;p&gt;example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myPromise.then((message) =&amp;gt; { 
    console.log(message);
}).catch((message) =&amp;gt; { 
    console.log(message);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  Async functions - making promises friendly
&lt;/h6&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function" rel="noopener noreferrer"&gt;async functions&lt;/a&gt; and the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await" rel="noopener noreferrer"&gt;await&lt;/a&gt; keyword, added in ECMAScript 2017.&lt;br&gt;
These features basically act as syntactic sugar on top of promises, making asynchronous code easier to write and to read afterwards.&lt;/p&gt;
&lt;h6&gt;
  
  
  The Async Keyword
&lt;/h6&gt;

&lt;p&gt;First of all we have the async keyword, which you put in front of a function declaration to turn it into an async function. An async function is a function that knows how to expect the possibility of the await keyword being used to invoke asynchronous code.&lt;/p&gt;

&lt;p&gt;They allow you to write promise-based code as if it were synchronous, but without blocking the main thread. They make your asynchronous code less "clever" and more readable.&lt;/p&gt;

&lt;p&gt;Async functions work like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function myFirstAsyncFunction() {
  try {
    const fulfilledValue = await promise;
  }
  catch (rejectedValue) {
    // …
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you use the async keyword before a function definition, you can then use await within the function. When you await a promise, the function is paused in a non-blocking way until the promise settles. If the promise fulfills, you get the value back. If the promise rejects, the rejected value is thrown.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Logging a fetch&lt;/strong&gt;&lt;br&gt;
Say we wanted to fetch a URL and log the response as text. Here's how it looks using promises:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function logFetch(url) {
  return fetch(url)
    .then(response =&amp;gt; response.text())
    .then(text =&amp;gt; {
      console.log(text);
    }).catch(err =&amp;gt; {
      console.error('fetch failed', err);
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's the same thing using async functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function logFetch(url) {
  try {
    const response = await fetch(url);
    console.log(await response.text());
  }
  catch (err) {
    console.log('fetch failed', err);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's the same number of lines, but all the callbacks are gone. This makes it way easier to read, especially for those less familiar with promises.&lt;/p&gt;

&lt;h6&gt;
  
  
  Adding error handling
&lt;/h6&gt;

&lt;p&gt;And if you want to add error handling, you've got a couple of options.&lt;/p&gt;

&lt;p&gt;You can use a synchronous try...catch structure with async/await. This example expands on the first version of the code we showed above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function myFetch() {
  try {
    let response = await fetch('coffee.jpg');

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    let myBlob = await response.blob();
    let objectURL = URL.createObjectURL(myBlob);
    let image = document.createElement('img');
    image.src = objectURL;
    document.body.appendChild(image);

  } catch(e) {
    console.log(e);
  }
}

myFetch();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The catch() {} block is passed an error object, which we've called e; we can now log that to the console, and it will give us a detailed error message showing where in the code the error was thrown.&lt;/p&gt;

&lt;p&gt;If you wanted to use the second (refactored) version of the code that we showed above, you would be better off just continuing the hybrid approach and chaining a .catch() block onto the end of the .then() call, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function myFetch() {
  let response = await fetch('coffee.jpg');
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return await response.blob();

}

myFetch().then((blob) =&amp;gt; {
  let objectURL = URL.createObjectURL(blob);
  let image = document.createElement('img');
  image.src = objectURL;
  document.body.appendChild(image);
})
.catch((e) =&amp;gt;
  console.log(e)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is because the .catch() block will catch errors occurring in both the async function call and the promise chain. If you used the try/catch block here, you might still get unhandled errors in the myFetch() function when it's called.&lt;/p&gt;

&lt;p&gt;Reference :- &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await" rel="noopener noreferrer"&gt;developer.mozilla.org&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>What is Throttling and Debouncing in JavaScript and how it works?</title>
      <dc:creator>Santan Sharma</dc:creator>
      <pubDate>Sat, 04 Sep 2021 09:54:51 +0000</pubDate>
      <link>https://dev.to/santansharma/what-is-throttling-and-debouncing-in-javascript-and-how-it-works-129o</link>
      <guid>https://dev.to/santansharma/what-is-throttling-and-debouncing-in-javascript-and-how-it-works-129o</guid>
      <description>&lt;p&gt;Event Listeners help us in binding functions which are called when that event is emitted, like scrolling or resizing.&lt;/p&gt;

&lt;p&gt;But what if the event is called multiple times in a very short span of time? If the function called by the listener is intensive, it can severely impact performance.&lt;/p&gt;

&lt;p&gt;Debouncing and Throttling are really useful under such scenarios.&lt;/p&gt;

&lt;h1&gt;
  
  
  Throttling
&lt;/h1&gt;

&lt;p&gt;Imagine yourself as a 7-year-old toddler who loves to eat chocolate cake! Today your mom has made one, but it's not for you, it's for the guests! You, being spunky, keep on asking her for the cake. Finally, she gives you the cake. But, you keep on asking her for more. Annoyed, she agrees to give you more cake with a condition that you can have the cake only after an hour. Still, you keep on asking her for the cake, but now she ignores you. Finally, after an interval of one hour, you get more cake. If you ask for more, you will get it only after an hour, no matter how many times you ask her.&lt;/p&gt;

&lt;p&gt;This is what throttling is!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Throttling is a technique in which, no matter how many times the user fires the event, the attached function will be executed only once in a given time interval.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For instance, when a user clicks on a button, a helloWorld function is executed which prints Hello, world on the console. Now, when throttling is applied with 1000 milliseconds to this helloWorld function, no matter how many times the user clicks on the button, Hello, world will be printed only once in 1000 milliseconds. Throttling ensures that the function executes at a regular interval.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$("body").on('scroll', _.throttle(function() {
  // Do expensive things
}, 100));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Debouncing
&lt;/h1&gt;

&lt;p&gt;Debouncing is delaying a certain execution to accomodate all changes before executing the final function.&lt;/p&gt;

&lt;p&gt;It’s very similar to throttle except the time delay is refreshed every time the event is triggered.&lt;/p&gt;

&lt;p&gt;Suppose the time delay provided is 500 milliseconds, and the event is triggered for 3 seconds, the function will only run once after 3.5 seconds.&lt;/p&gt;

&lt;p&gt;Again the important part here is that you’re not guaranteed that the function will trigger at least once in the given delay time instead the delay time gets updated every time the function is called.&lt;/p&gt;

&lt;p&gt;This is particularly useful in cases where the &lt;strong&gt;function needs to be fired only once for the final output and previous calls can be ignored in case of continuous triggers.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One example would be search input triggers. If you’re binding to the change event of the input to update the results, it is usually not preferred to send API calls for every letter that is typed. If we are rather waiting for 2 seconds before ensuring that there are no further changes from the user before sending the final request, it will significantly reduce the amount of API calls made.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(window).on('resize', _.debounce(function() {
  // Do expensive things
}, 100));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hope this helps! Throttle up!&lt;/p&gt;

&lt;p&gt;Enjoyed this article?&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>What is Hoisting and how it works in JavaScript?</title>
      <dc:creator>Santan Sharma</dc:creator>
      <pubDate>Tue, 31 Aug 2021 18:30:57 +0000</pubDate>
      <link>https://dev.to/santansharma/what-is-hoisting-and-how-it-works-in-javascript-3lan</link>
      <guid>https://dev.to/santansharma/what-is-hoisting-and-how-it-works-in-javascript-3lan</guid>
      <description>&lt;p&gt;Hoisting is JavaScript concept which make JavaScript different from language Java.&lt;/p&gt;

&lt;p&gt;In Java every variable created in code have block level scope. Means if we have create any variable that will have its visibility limited into that block in which it was declared.&lt;/p&gt;

&lt;p&gt;So if we use variable above from the declaration it will gives error.&lt;/p&gt;

&lt;p&gt;But in the JavaScript, the variables can be used before declared, this kinds of mechanism is called Hoisted. It’s a default behavior of JavaScript.&lt;/p&gt;

&lt;p&gt;Hoisting is JS’s default behavior of defining all the declarations at the top of the scope before code execution. One of the benefits of hoisting is that it enables us to call functions before they appear in the code. JavaScript only hoists declarations, not initializations. You can find the official documentation &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var" rel="noopener noreferrer"&gt;Here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Understanding what exactly is JavaScript Hoisting&lt;br&gt;
Variable declaration and initialization occur in the following sequence:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Declaration –&amp;gt; Initialization/Assignment –&amp;gt; Usage&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Variable lifecycle
let x;                 // Declaration
x = “hoisting”;        // Assignment
console.log(x);        // Usage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Most importantly, you should always remember that the JavaScript declares the variable first in the background. Then, initializing them. Thus, it is also good to know that the processing of variable declarations takes place before the execution of any code. However, until the execution of code assigning them takes place the undeclared variables do not exist in JavaScript.&lt;br&gt;
Therefore, when the assignment is executed, a value assigned to an undeclared variable implicitly creates it as a global variable. This specifies that all undeclared variables are global variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// hoisting
function Hoisting(){
  x = 100;
  let y = 200;
}
Hoisting();
console.log(x); // 100
console.log(y); // Reference Error: y is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code sample, there is a function called Hoisting(). Thus, we have a variable which we didn’t declare using let/var/const and a let variable y. The assigning of the undeclared variable to the global scope is done by JavaScript. But for variable y, we get a ReferenceError.&lt;/p&gt;

&lt;h1&gt;
  
  
  Hosting in Function scoped variable
&lt;/h1&gt;

&lt;p&gt;In ES5, we consider the var keyword. Hoisting with var is somewhat different in comparison to let/const. The example with var to see how hoisting works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var num (global)
console.log(car);    // undefined
var car = ‘Lamborgini’;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, when logging the variable name which was declared and assigned later than using it, the compiler gives an “undefined” result. This was not expected as we should have got ReferenceError as trying to use the car variable even before declaring it.&lt;br&gt;
But the interpreter sees this differently, which is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//how interpreter sees the above code
var car;
console.log(car); // undefined
car = ‘Lamborgini’;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  The let and const Keywords.
&lt;/h1&gt;

&lt;p&gt;Variables and constants declared with let or const are not hoisted!&lt;br&gt;
JavaScript Initializations are Not Hoisted&lt;br&gt;
JavaScript only hoists declarations, not initializations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = “volkswagon”; // Initialize a
var b = “Lamborgini”; // Initialize b
elem = document.getElementById("car"); // Find an element
elem.innerHTML = a + " " + b;       // Display a and b as volkswagon and lamborgini
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, since the declaring of variables takes place before the results. As a result, the execution of the code prints the result of variable a and b.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = “i10”;  // Initialize a
elem = document.getElementById("car");      // Find an element
elem.innerHTML = "a is " + a + “ and b is " + b;  // Display a and b
var b = “Lamborgini”;  // Initialize b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
a is i10 and b is undefined&lt;br&gt;
Hence, this is because only hoisting of the declaration (var b) takes place, not the initialization (= “Lamborgini”) to the top. Because of hoisting, b has been declared before it is used, but because initializations are not hoisted, the value of b is undefined.&lt;/p&gt;
&lt;h1&gt;
  
  
  Hoisting classes
&lt;/h1&gt;

&lt;p&gt;JavaScript classes can be classified into two classes:&lt;/p&gt;

&lt;p&gt;*Class declarations&lt;br&gt;
*Class expressions&lt;/p&gt;

&lt;p&gt;In Class declarations&lt;br&gt;
They are much like function counterparts. Therefore, this means no hoisting of JavaScript class declarations. However, they remain uninitialized until evaluation. Thus, this effectively means that you have to declare a class before you can use it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var car1 = new car();
car1.height = 5;
car1.weight = 500;
console.log(car1);   // Output: ReferenceError: car is not defined
class car{
  constructor(height, weight) {
    this.height = height;
    this.weight = weight;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, the reference error occurs. This is because, after initialization of the car1 variable, the defining of car class is takes place. To solve this error, we just need to define the car class before car1 initialization. This is hosting in the class declaration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class car{
  constructor(height, weight) {
    this.height = height;
    this.weight = weight;
  }
}
var car1 = new car();
car1.height = 5;
car1.weight = 500;
console.log(car1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Therefore, this gives the proper result.&lt;br&gt;
In Class expressions&lt;br&gt;
They are much like their function counterparts. Therefore, this means no hoisting of class expression.&lt;br&gt;
Therefore, below is an example with the un-named or anonymous variant of the class expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var rect = new shapes();
rect.height = 10;
rect.width = 20;
console.log(rect); // Output: TypeError: shapes is not a constructor
var shapes = class {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
};
Thus, the correct way to do it is like this:
var shapes = class {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
};
var rect = new shapes();
rect.height = 10;
rect.width = 20;
console.log(rect);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;To many developers, Hoisting is an unknown behavior of JavaScript. Many developers overlook it’s importance as well. Moreover, if a developer doesn’t understand hoisting, programs may contain bugs (errors). In order to avoid bugs, always declare all variables at the beginning of every scope. Thus, this is how JavaScript interprets the code, it is always a good rule.&lt;/p&gt;

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