<?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: Sumudu Siriwardana</title>
    <description>The latest articles on DEV Community by Sumudu Siriwardana (@sumusiriwardana).</description>
    <link>https://dev.to/sumusiriwardana</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%2F640110%2F120e45d6-e6b9-4f5d-a246-4a88936a9200.jpg</url>
      <title>DEV Community: Sumudu Siriwardana</title>
      <link>https://dev.to/sumusiriwardana</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sumusiriwardana"/>
    <language>en</language>
    <item>
      <title>The Accessibility Story Behind Deprecated HTML Elements</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Fri, 20 Sep 2024 13:20:19 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/the-accessibility-story-behind-deprecated-html-elements-hfd</link>
      <guid>https://dev.to/sumusiriwardana/the-accessibility-story-behind-deprecated-html-elements-hfd</guid>
      <description>&lt;p&gt;I attended the &lt;a href="https://conference.webaim.org/" rel="noopener noreferrer"&gt;Web Accessibility in Mind Conference&lt;/a&gt; a few weeks ago, and the sessions gave me valuable new perspectives on accessibility. I kept thinking about some of the design choices we make when developing products and services as developers, product managers, designers, or anyone contributing to them and how we can advocate designing for an inclusive and equitable user experience with these choices. &lt;/p&gt;

&lt;p&gt;Interestingly, right after the conference, I came across a cool design created with a &lt;code&gt;marquee&lt;/code&gt; tag. It explained how easy it was to use this HTML element and whether we should bring it back since it was deprecated in HTML5. As "accessibility" kept running through my mind, that design made me think about why some HTML elements, once so popular, are now deprecated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are HTML elements deprecated?
&lt;/h2&gt;

&lt;p&gt;Over time, with evolving web technologies and a better understanding of how to structure and style content and pages, they were eventually deprecated as better ways for structuring and styling content emerged. Although these elements were deprecated, they are sometimes still available due to backward compatibility and their future removal (which we call "sunsetting" a feature). So, we can still use some of these elements, but they are discouraged to use for valid reasons.&lt;/p&gt;

&lt;p&gt;There are several reasons for deprecating these elements. One main reason is the separation of concerns. Once the HTML standard introduced the versioning system, CSS and JavaScript became the norm for handling styling and behavior. The role of HTML shifted to focusing solely on structuring the content. This separation made some older HTML elements that blended structure and styling, such as &lt;code&gt;font&lt;/code&gt;, &lt;code&gt;big&lt;/code&gt;, and &lt;code&gt;small&lt;/code&gt;, redundant and eventually led to their deprecation.&lt;/p&gt;

&lt;p&gt;Accessibility has also been a key factor in deprecating some HTML elements. Some older HTML elements, like &lt;code&gt;marquee&lt;/code&gt; and &lt;code&gt;blink&lt;/code&gt;, were not designed with accessibility in mind, making these tags visually distracting and also making it difficult for screen readers and other assistive technologies to interpret or interact with the content properly. Some of these elements could even cause a health hazard. For example, flashing or blinking content can trigger seizures in someone with photosensitive epilepsy. So, there are &lt;a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/seizure-does-not-violate.html" rel="noopener noreferrer"&gt;technical requirements issued by WCAG 2.0 from W3C&lt;/a&gt; for flashing and flickering contents. This emphasis on accessibility led to the deprecation of several HTML elements, which prioritized visual effects over user inclusivity.&lt;/p&gt;

&lt;p&gt;Let's dive into a few specific examples to understand why they were deprecated and how we can learn from these decisions to build better, more accessible websites.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Accessibility Story Behind Deprecated HTML Elements
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;marquee&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Microsft introduced the &lt;code&gt;marquee&lt;/code&gt; tag in the 1990s. Remember those old, retro websites with moving text or images? Those classic screen savers with floating shapes and text? While it was fun and impressive to develop web pages with this effect, it was not supported across all browsers and was not a part of any official HTML standard. Soon, developers realized the main issues and the accessibility problems it was causing.&lt;/p&gt;

&lt;p&gt;One of the main accessibility problems with this effect was that the constantly moving text was distracting, and there was no option for users to stop scrolling except to close the web page. Even worse, screen readers struggled to interpret the content within a  element. Those who relied on assistive technologies could easily miss important information. Because of these issues, the &lt;code&gt;marquee&lt;/code&gt; element was deprecated.&lt;/p&gt;

&lt;p&gt;However, the concept of moving text or images is not obsolete. Although you can still use this tag, it's better to avoid using it. Instead, we can use  CSS and JavaScript to design the same effect with accessibility in mind, providing controls for users to pause or stop animations if they find it distracting. While creating impressive visual designs, it's important to ensure they are accessible to everyone and follow accessibility guidelines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. &lt;code&gt;blink&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Netscape introduced the &lt;code&gt;blink&lt;/code&gt; element a few months before Microsoft introduced the &lt;code&gt;marquee&lt;/code&gt;. This tag did exactly what it sounds like, giving the text a blink effect. Like the &lt;code&gt;marquee&lt;/code&gt;, web creators used this tag to grab users' attention. They created visually stand-out content to highlight special offers, warnings, or anything that should be highlighted on web pages.&lt;/p&gt;

&lt;p&gt;Some users found this blinking effect really annoying, and it also caused serious accessibility issues. Users with cognitive disabilities might find it really hard to focus on other parts of the page due to this effect. Also, flashing or blinking content can trigger seizures in someone with photosensitive epilepsy, which makes this effect dangerous to some and a potential health hazard.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;blink&lt;/code&gt; was eventually decreased due to these concerns and was never a part of HTML standards. Although we can use CSS and JavaScript to create the same effect, ensuring the design follows the accessibility standard is important since it can cause serious harm to some users. If you want to refresh your mind on the technical requirements for flashing and flickering contents, check the &lt;a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/seizure-does-not-violate.html" rel="noopener noreferrer"&gt;guideline issued by WCAG 2.0 from W3C here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. &lt;code&gt;frameset&lt;/code&gt; and &lt;code&gt;frame&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Netscape introduced the &lt;code&gt;frame&lt;/code&gt; and &lt;code&gt;frameset&lt;/code&gt; in 1996. The primary use of these tags is to split a website into different sections or frames to display multiple documents in a single view. Designers and developers could improve the page loading time by separating elements of the web page, like headers and navigation bars, from the main content. This was useful back then when most users had slow internet connections.&lt;/p&gt;

&lt;p&gt;Although they improved the loading time, frames introduced a whole set of usability and accessibility issues. For example, frames made it difficult for users to bookmark specific pages or use the back button effectively. Also, frames were not compatible with responsive web design. One of the major accessibility issues was that the content inside frames was difficult to access and index, making websites less accessible and harder to find.&lt;/p&gt;

&lt;p&gt;Instead of frames, we can create better layouts and complex, responsive designs that work seamlessly across all devices with CSS Flexbox and Grid. Modern layout tools provide far greater control and accessibility than frames ever could.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. &lt;code&gt;applet&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;applet&lt;/code&gt; was introduced with HTML 3.2, released in 1997, and it was highly popular during the mid-to-late 1990s due to the rich possibilities of adding interactive content to websites. Java applets brought an exciting and new level of interactivity to the web by enabling features like games, dynamic charts, and media playback.&lt;/p&gt;

&lt;p&gt;However, besides the security and compatibility issues, the &lt;code&gt;applet&lt;/code&gt; created major problems for accessibility. The content inside a Java applet was often a black box to screen readers and other assistive technologies. For users with disabilities, this issue made it nearly impossible to interact with or even understand the content within the applet.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;applet&lt;/code&gt; element was deprecated when the HTML 4.01 specification was released in December 1999. We can now create more secure, accessible, and widely supported interactions on websites using JavaScript and other web technologies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. &lt;code&gt;dir&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;dir&lt;/code&gt; was introduced to create multi-column directory lists, specifically to present a list of items, such as file directories or links, in a compact format. However, it wasn't as flexible or semantically clear as the &lt;code&gt;ul&lt;/code&gt; (unordered list) and &lt;code&gt;ol&lt;/code&gt; (ordered list) that we commonly use today.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ul&lt;/code&gt; and &lt;code&gt;ol&lt;/code&gt; tags allow us to create accessible lists by providing clear, structured ways to present information with better semantic meaning, making it easier for screen readers and other assistive technologies to interpret the content. So, the &lt;code&gt;ul&lt;/code&gt; tag became the standard when the &lt;code&gt;dir&lt;/code&gt; was deprecated in HTML 4.01.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why understanding deprecated elements matters
&lt;/h2&gt;

&lt;p&gt;As web designers and developers, it's important to understand the reasoning behind these deprecations to know why certain elements were phased out. This could be related to several factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Separation of concerns:&lt;/strong&gt; Keeping content structure (HTML), style (CSS), and behavior (JavaScript) separate allows for cleaner, more maintainable code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security:&lt;/strong&gt; Elements like &lt;code&gt;applet&lt;/code&gt; introduced security vulnerabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accessibility:&lt;/strong&gt; Older HTML elements like &lt;code&gt;marquee&lt;/code&gt; and &lt;code&gt;blink&lt;/code&gt; were not designed with accessibility in mind and created barriers and issues for users with disabilities.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By understanding these factors, we can make more informed choices in our design and development practices, ensuring that we avoid past mistakes and create more accessible, user-friendly websites.&lt;/p&gt;

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

&lt;p&gt;While it's fun to look back at the quirky, nostalgic elements of early web design, we must prioritize inclusivity and accessibility in modern web development. The decisions we make today will shape users' experiences tomorrow. So, when tempted to use impressive visual effects, remember the lessons from deprecated HTML elements and make sure your designs are accessible to everyone.&lt;/p&gt;




&lt;p&gt;Feel free to connect with me on &lt;a href="https://x.com/sumusiriwardana" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;, &lt;a href="https://www.linkedin.com/in/sumudusiriwardana/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, and &lt;a href="https://medium.com/@sumudusiriwardana" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;! 😊&lt;/p&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>a11y</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Dealing With Difficult Stakeholders</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Mon, 05 Aug 2024 15:55:07 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/dealing-with-difficult-stakeholders-3d3l</link>
      <guid>https://dev.to/sumusiriwardana/dealing-with-difficult-stakeholders-3d3l</guid>
      <description>&lt;p&gt;Anything that involves humans is bound to come with its fair share of complexities. Whether it's working on a team project, managing a household, or even just navigating daily interactions, human behavior's unpredictability can throw unexpected challenges your way. In any project, product, or business, managing stakeholders isn't just a box to check off. It's the foundation of success. Your stakeholders' support can make or break your project. That doesn't mean that you have to say yes to everyone and make everyone happy all the time, which is impossible. However, whether you're a project manager, a team leader, or anyone leading a project, product, or business, knowing how to navigate difficult conversations, tackle challenging situations, and remove roadblocks is essential to keep things moving forward.&lt;/p&gt;

&lt;p&gt;While I only had a brief module on stakeholder management during my PM studies, the real lessons came from years of hands-on experience, learning through trial and error. Over time, I discovered that building long-term, trustworthy relationships with stakeholders is not only key to success but also essential for effectively managing difficult situations. It's about knowing when to stand your ground, when to compromise, and always keeping the project's best interests at heart. Here are a few tips I've learned along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  1.   Prioritize Stakeholders
&lt;/h2&gt;

&lt;p&gt;When dealing with challenging stakeholders and potential issues, the first step is to map out all the stakeholders involved and understand their level of influence and interest in the project or product. This will help you identify at least one stakeholder who might pose challenges or have high demands throughout the project cycle. By being proactive and planning your communication, engagement, and information sharing strategies with these stakeholders, you can lower the chances of conflicts in the future and gain their early collaboration.&lt;/p&gt;

&lt;p&gt;Remember that the intention here is not to categorize stakeholders as "good" or "bad." Instead, it is to identify potential risks of future conflicts that could cause project delays or obstacles. This method has always helped me identify all the relevant stakeholders, establish relationships positively and early on, and monitor them closely. It's all about building good relationships and ensuring everything runs smoothly.&lt;/p&gt;

&lt;h2&gt;
  
  
  2.   Set Clear Expectations
&lt;/h2&gt;

&lt;p&gt;You've probably heard the saying, "Prevention is better than cure." One of the best ways to prevent conflicts with stakeholders is by setting clear expectations from the start. By laying out what's expected and possible, you create a foundation for smoother collaboration, reducing misunderstandings and aligning everyone towards common goals.&lt;/p&gt;

&lt;p&gt;At the beginning of every project, during the kickoff meeting, I take the time to clearly explain the goals, timelines, limitations, everyone’s role, and communication methods, including how often we'll check in. I make sure everyone understands and addresses any concerns right away. Also, whenever I set up meetings with stakeholders, I ensure that the agenda is clear, and the expected outcomes are communicated in advance. This approach has consistently helped get everyone on the same page from the start, avoiding surprises and minimizing misunderstandings down the road.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.   Constant Communication
&lt;/h2&gt;

&lt;p&gt;James Clear wisely said, "It's generally better to over-communicate. Silence frustrates and confuses people. Better to communicate early and often." This is especially true when it comes to stakeholder management. Good communication is essential in any relationship, but great communication is what builds trust. It's not just about showing stakeholders that you're on top of things, reliable, and working in their best interest. It's also about keeping the lines of communication open for feedback, sharing information proactively, and trusting them to make informed decisions based on regular updates.&lt;/p&gt;

&lt;p&gt;For example, imagine your client is expecting a feature release in the next quarter, something the management has promised. However, your team is concerned that they may not be able to deliver on time and might need to push the release to the following quarter. While it might be uncomfortable to share this news with the client, it's crucial that they're informed about the situation as early as possible. This way, they can make an educated decision and discuss alternative solutions, rather than waiting until the next quarter and facing disappointment and potential conflict when the feature isn't delivered as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  4.   Be Kind, Empathetic, and Diplomatic
&lt;/h2&gt;

&lt;p&gt;Dealing with difficult situations requires a lot of diplomacy and emotional intelligence. Most of the time, to a stakeholder's eyes, you're seen as the bouncer or the gatekeeper. But instead of closing doors, keep them open. Show them you're always ready to listen, collaborate, address their concerns, and fix issues. Melt them with kindness, and you'll find that even the most difficult stakeholders can become more cooperative and open to collaboration.&lt;/p&gt;

&lt;p&gt;I once took over an internal project halfway through, relying on shared resources from another unit. These team members were crucial for meeting our deadline, but they couldn't allocate the necessary time because of their workload under their unit head. I've been trying to schedule a meeting with the unit head for weeks to discuss the issue, but he hasn't given me an opportunity. I also couldn't catch him for a casual chat because he's been avoiding me. After a few more deliberate attempts and with some help from another colleague, I was finally able to set up a meeting with him to discuss the issue.&lt;/p&gt;

&lt;p&gt;At first, he was reluctant to be open and mentioned the workload and high priorities of his team, which I had already checked and knew were lower than he suggested. But after some back and forth conversation and actively listening to his concerns and reasoning, I realized the real issue. The team members had been assigned to my project without consulting him first, and he felt threatened by the loss of control over his team. I apologized for the oversight and promised to keep him informed about task timelines and priorities, ensuring he'd be involved in future resource-sharing discussions. This approach helped us solve the problem and strengthened our working relationship for the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  5.   Understand Their Needs and Listen Carefully
&lt;/h2&gt;

&lt;p&gt;When dealing with difficult stakeholders, it's important to recognize that they're often pushing for something they deeply care about, whether it's their team's success, meeting specific targets, or ensuring the needs of end-users are met. Instead of looking at their demands as obstacles, listen carefully and try to understand the underlying reasons behind them. What pressures are they under? What are they trying to achieve?&lt;/p&gt;

&lt;p&gt;The "5 Whys" technique can help answer these questions and uncover the root cause. Often, the initial conversation only scratches the surface, and stakeholders may not immediately reveal what they want and why they're resistant or unhappy. Sometimes, they might need help understanding the root cause themselves. It's your job to ask, "Why do you think that is?" or "Why do you feel that way?" after each response, digging deeper to uncover the real demand or issue. By seeing the situation from their perspective and getting to the heart of the matter, you can find common ground and work towards a solution that benefits everyone.&lt;/p&gt;

&lt;h2&gt;
  
  
  6.   Address the Root Cause
&lt;/h2&gt;

&lt;p&gt;Suppose you don't address the root causes of the issues as early as possible. In that case, you'll find yourself constantly dealing with and negotiating with stakeholders, which may become increasingly difficult over time. Stakeholders won't trust you just because you're diplomatic, kind, and easy to work with. They'll trust you when you resolve their issues and get the work done. So, it's crucial to identify root causes, find solutions, plan fixes, and communicate clearly with your stakeholders about when those issues will be resolved.&lt;/p&gt;

&lt;p&gt;I once had a team member who was disengaged during our retrospective meetings. I tried adding some fun activities to encourage participation, but it didn't work. During a one-on-one meeting, he explained that he didn't see the point of retrospectives if we weren't actually having serious conversations and implementing the solutions we discussed. In his previous teams, retrospectives had become just a routine of noting down things without real action.&lt;/p&gt;

&lt;p&gt;This feedback gave me a new perspective. It made me realize the importance of addressing concerns and root causes immediately. After this conversation, we made retrospectives a time to celebrate wins, truly solve the team's issues, and find ways to improve rather than just going through the motions. By focusing on real solutions and meaningful conversations, we were able to create a more productive, trustworthy, and engaged environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  7.   Negotiate and Find Common Ground
&lt;/h2&gt;

&lt;p&gt;Managing difficult stakeholders is not so different from negotiating with a lawyer. They're meticulous, relentless, and always looking for the slightest advantage. You need to be well-prepared, stay calm under pressure, and be ready to find common ground without giving up too much. But remember, it isn't about winning. It's about finding a solution that works for everyone involved. When working with difficult stakeholders, start by looking for areas where your goals align with theirs. Focus on these commonalities to build a foundation for collaboration, ensuring that both sides feel heard and valued.&lt;/p&gt;

&lt;p&gt;However, there will be times when you can't get everything you want. In these situations, being ready to compromise is key. Flexibility shows that you're committed to finding a solution that benefits everyone, even if it means adjusting your own expectations. By finding a middle ground, you can resolve conflicts and keep the project on track, all while maintaining strong, cooperative relationships with your stakeholders.&lt;/p&gt;

&lt;h2&gt;
  
  
  8.   Don’t Take Things Personally
&lt;/h2&gt;

&lt;p&gt;If you take criticism and closed-off reactions personally, you're setting yourself up for a rough ride throughout your projects. The work is never about you. Stakeholders often have reasons for disagreements and conflicts, and while it's easy to internalize that as something personal, it's important to recognize that it's usually not the case.&lt;/p&gt;

&lt;p&gt;This doesn't mean you have to put up with rude behavior or discrimination (handling that deserves a post of its own). In my previous experience, that unit head kept rejecting my meeting requests and avoiding me altogether, and it would have been easy to assume he had something against me personally. But the reality was, he didn't even know me, and his frustration was rooted entirely in something else. The real issue was that his team members were being reassigned without his approval.&lt;/p&gt;

&lt;p&gt;In situations like these, it's important to step back and consider why someone is acting the way they are. By not jumping to conclusions and taking things personally, you can begin to understand the real issue at hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  9.   Saying 'No' the Right Way
&lt;/h2&gt;

&lt;p&gt;Steve Jobs once said, "Focusing is about saying no." But let's be honest, saying "no" is easier said than done. It's even harder to do it without burning bridges or coming across as rude. Yet, pushing back in certain situations is necessary, and being assertive without being rude is not always easy.&lt;/p&gt;

&lt;p&gt;When working on projects, you're often faced with requests, ideas, or demands that may not align with the project's goals, and saying "no" becomes essential to maintaining focus and ensuring the project's success. The goal is to be assertive without coming across as harsh. Start by understanding the request thoroughly and gathering any necessary data or research to support your decision. When you push back, explain your reasoning clearly, showing that it's not a personal rejection but a decision based on the project's best interests.&lt;/p&gt;

&lt;p&gt;Always choose the right communication channels, and back up your reasoning with solid research, data, and information. I highly recommend setting up a meeting or video call instead of explaining things over email. Text is a one-way communication, and your message can easily be misinterpreted. But when you're face-to-face, whether in person or via video, you have the chance to explain your decision, counter with data, and ultimately gain stakeholder buy-in without burning bridges in the process.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;When it comes to managing stakeholders, teams, or clients, there’s no one-size-fits-all approach. Every person, relationship, and situation is different, and that’s what makes human interactions both challenging and rewarding. Instead of rigid instructions, we rely on guidelines, best practices, and shared experiences to navigate these complexities. Success in these situations lies in your ability to understand the unique dynamics at play and adapt your approach to match them, build trust, and foster an environment where collaboration can thrive, even when things get tough.&lt;/p&gt;

&lt;p&gt;Every experience brings new lessons, and we all have our own ways of navigating tough stakeholder relationships. What’s worked for you? Share your advice and experiences in the comments!&lt;/p&gt;




&lt;p&gt;Feel free to connect with me on &lt;a href="https://x.com/sumusiriwardana" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;, &lt;a href="https://www.linkedin.com/in/sumudusiriwardana/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, and &lt;a href="https://medium.com/@sumudusiriwardana" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;! 😊&lt;/p&gt;

</description>
      <category>projectmanagement</category>
      <category>stakeholders</category>
      <category>productmanagement</category>
    </item>
    <item>
      <title>Mastering the PMP Exam: Essential Tips for Success</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Tue, 25 Jun 2024 13:08:59 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/mastering-the-pmp-exam-essential-tips-for-success-3j86</link>
      <guid>https://dev.to/sumusiriwardana/mastering-the-pmp-exam-essential-tips-for-success-3j86</guid>
      <description>&lt;p&gt;Last month, I attended my first PMI chapter meeting, where I was seated with two other members next to me, one who had earned her PMP a year ago and another who was still preparing for the exam. As we introduced ourselves, our conversation naturally flowed into our experiences with the PMP exam, study processes, and resources. I took the PMP exam online that morning and was nervously waiting for the results. The next day, I was over the moon to see that I had passed with “Above Target” scores in all three domain areas.&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%2Fuploads%2Farticles%2Ft1aoh37l2r76ysncg5hy.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%2Fuploads%2Farticles%2Ft1aoh37l2r76ysncg5hy.png" alt="My PMP certification and the results breakdown."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparation and Resources
&lt;/h2&gt;

&lt;p&gt;It took me nearly three weeks to study and prepare for the PMP exam. I was already familiar with the PMP processes and agile concepts through my CAPM and CSM certificates and had almost a decade of work experience. Even so, preparing for and sitting through this four-hour exam can be time-consuming, confusing, challenging, and stressful. Therefore, I thought of sharing my experience, a few resources, and tips that might help you strategize your study plan and exam prep.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;There are many resources available to prepare for the PMP exam. To maximize the efficiency of my study, I applied the Pareto principle. After thoroughly researching the options and considering what would best suit my study methods, I selected a few key resources besides the PMBOK and Agile Practice Guide by PMI to maximize my learning and results.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;a href="https://www.udemy.com/course/pmp-certification-exam-prep-course-pmbok-6th-edition/" rel="noopener noreferrer"&gt;PMP Certification Exam Prep Course by Andrew Ramdayal&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Once I decided to take the PMP exam, I enrolled in this course to earn the Professional Development Units (PDUs) necessary for the PMP application process. Andrew has structured the course in a very simple and easy-to-understand manner, dividing it into sections based on traditional, agile, and hybrid methods, ethics, mindsets, and tips. Even if you have a certified PMI trainer to earn your PDUs, I recommend checking out &lt;a href="https://www.youtube.com/@AndrewRamdayal" rel="noopener noreferrer"&gt;Andrew’s YouTube channel&lt;/a&gt;, where he posts all his tutorials and tips.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;a href="https://store.rmcls.com/pmp-exam-prep-eleventh-edition" rel="noopener noreferrer"&gt;Rita Mulcahy’s PMP Exam Prep&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This book is very helpful in understanding the PMBOK and the various process groups, including agile methodologies. It provides the necessary guidelines and tips on what PMI expects and what to anticipate on the exam. Additionally, each chapter includes practice questions to test your knowledge and identify weak areas.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;a href="https://www.youtube.com/@davidmclachlanproject" rel="noopener noreferrer"&gt;David McLachlan’s YouTube Channel&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This channel offers tutorials, questions, and explanations that are extremely helpful for students at any level in understanding concepts and answering questions. During his question videos, he also teaches how to break down the question into parts, use keywords to identify answers, eliminate options, and strategically align responses with concepts.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;a href="https://tiaexams.com/course/tiapmpsimulator" rel="noopener noreferrer"&gt;TIA Exam Simulator by Andrew Ramdayal&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This simulator includes six mock exams and video explanations for each question. It helps you understand how to break down questions and select the correct answers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Study Tips
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Understand your learning style:
&lt;/h3&gt;

&lt;p&gt;Unless you have a photographic memory or enjoy reading big books and memorizing them, reading the PMBOK and other materials from start to finish can be frustrating and unproductive. Understanding your learning style and how you comprehend fundamentals is crucial in preparing for this exam. I prefer to break down topics and simultaneously use videos and reading materials to grasp the concepts. I then explain these concepts verbally or in writing to reinforce my understanding and identify gaps. I applied this learning style to understand new concepts and remember old ones, using Andrew’s videos, PMI materials, and Rita’s book as references.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Do not just memorize the topics:
&lt;/h3&gt;

&lt;p&gt;The PMP exam consists of situational questions where you need to understand a scenario and apply your knowledge to achieve the best possible outcome. You need a deep understanding of the knowledge areas, process groups, and processes. Once you grasp these concepts, you can logically identify the inputs, tools &amp;amp; techniques, and outputs (ITTOs) associated with each process without memorizing them. It's essential to understand them well enough to recognize the current process when faced with a situation or technique, determine what actions to take, and identify the next steps. Additionally, understand the concepts behind each formula as much as the calculations themselves. The questions focus more on interpreting a situation based on the formula results than the calculations alone.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Learning the Mindset:
&lt;/h3&gt;

&lt;p&gt;One of the most valuable tips I got from Andrew’s course is understanding how to develop the necessary mindset. Shifting from a plan-driven to a change-driven mindset and adopting the PMI mindset despite years of experience is crucial for tackling each question. Situational questions are designed to identify whether the scenario is plan-driven, change-driven, or hybrid, and you must choose the best answer accordingly. It's important always to prioritize servant leadership, face-to-face communication, minimizing escalations, inclusivity, proactive management, and adherence to standards and regulations.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Set a realistic goal and deadline:
&lt;/h3&gt;

&lt;p&gt;It’s important to understand your schedule and how much effort and energy you can invest, and based on that, set a realistic deadline for yourself. Many people apply for the exam and wait until they feel fully prepared before scheduling it. However, time tends to expand without a clear deadline, leading to procrastination and delaying the exam, often until the next curriculum change. Once you schedule the exam, you'll be motivated to ensure you are prepared by the exam date.&lt;/p&gt;

&lt;p&gt;When I was applying, I had some free time to prepare, so once my application was approved, I scheduled my exam for one week later, knowing I had a whole week to dedicate to longer study sessions. Familiarity with the concepts and the right mindset helped me fast-track my revision and focus more on practice. If I had set the date further in the future, I might have lost momentum and motivation to meet the deadline.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Practice, Practice, and Practice
&lt;/h3&gt;

&lt;p&gt;The best way to prepare for the exam is through practice. Utilize questions from simulators, YouTube, and other sites to test your knowledge and apply what you’ve learned, even though they might not be as challenging as actual PMP questions. Practicing these questions allows you to reinforce what you’ve learned, which is extremely helpful for remembering concepts. I used questions from Rita’s book, Andrew’s TIA simulator, and David’s YouTube channel. These resources helped me understand the types of scenarios to expect and learn how to break down these questions to find the correct answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exam Tips
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Exam Day Preparation
&lt;/h3&gt;

&lt;p&gt;I took the exam online because I preferred the comfort of my own environment rather than driving to an unfamiliar location. When taking the exam online, having a completely distraction-free and isolated space is crucial. Proctors monitor and inspect you through a webcam during the exam. Once you log into the system, they will ask you to show your surroundings and inspect all your items. Ensure you don’t keep anything on your desk except the laptop. The proctors will stay with you until you finish the exam, so make sure no one enters your sitting area, maintain quietness, and remain seated unless you are allowed to take a break. Breaking any of these rules will immediately result in being thrown out of the system and having your exam canceled.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Maintaining Focus
&lt;/h3&gt;

&lt;p&gt;This is a long, stressful exam, and you must be 100% focused for 4 hours to understand the subtle differences between questions and each answer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make sure you have a good meal before the exam.&lt;/li&gt;
&lt;li&gt;Keep a glass of water to stay hydrated, but don’t drink too much.&lt;/li&gt;
&lt;li&gt;Ensure you have a reliable internet connection and power.&lt;/li&gt;
&lt;li&gt;Take the two 10-minute breaks during the exam. They’ll help you refresh your mind, move around, and use the restroom.&lt;/li&gt;
&lt;li&gt;If you don’t like white mode and can’t stare at the screen for a long time, reduce the brightness of your screen before your eyes get blurry.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Answering the Questions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;One strategy I used to identify whether a question belongs to traditional, agile, or hybrid methods is to look for keywords. If the question mentions keywords related to a particular method, I filter the answers corresponding to that method.&lt;/li&gt;
&lt;li&gt;If the question is too long, I first read the answers to get an idea, then the last sentence of the question, and finally, the whole question. This helped me quickly understand the scenario and highlight the keywords.&lt;/li&gt;
&lt;li&gt;I used the elimination method to filter answers. Often, at least two answers can be eliminated due to irrelevance, leaving two very similar answers that are hard to choose between if you don’t have the right mindset.&lt;/li&gt;
&lt;li&gt;Leverage the right mindset, not just experience, to understand the first, next, and best options and select the correct answer.&lt;/li&gt;
&lt;li&gt;If you need more time to think or are unsure, flag the question and move on to the next one. You can review all flagged questions before submitting.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Earning the PMP certification requires knowledge, experience, and practice. It’s one of the most recognizable qualifications for a project manager or anyone who leads projects. I hope this helps you understand how to plan your study time and prepare for your exam. I would love to hear from you if you have any additional tips or resources to share or if you have any questions.&lt;/p&gt;

&lt;p&gt;Wishing everyone good luck on your journey to PMP success!&lt;/p&gt;




&lt;p&gt;Feel free to connect with me on &lt;a href="https://twitter.com/sumusiriwardana" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/sumudusiriwardana/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>projectmanagement</category>
      <category>pmp</category>
      <category>projectmanager</category>
      <category>learning</category>
    </item>
    <item>
      <title>Emotional Intelligence: The Key to Successful Project Management</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Thu, 04 May 2023 07:45:45 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/emotional-intelligence-the-key-to-successful-project-management-568o</link>
      <guid>https://dev.to/sumusiriwardana/emotional-intelligence-the-key-to-successful-project-management-568o</guid>
      <description>&lt;p&gt;Over the years, I have had the pleasure of working with some phenomenal leaders who prioritize building high-performing teams while fostering strong relationships with all stakeholders. They possess charming personalities and never let stress get the best of them. What makes these leaders stand out is their Emotional Intelligence.&lt;/p&gt;

&lt;p&gt;Emotional intelligence, also known as EQ, is the ability to understand and manage one's own emotions, as well as the emotions of others. So why is it important for project management?&lt;/p&gt;

&lt;p&gt;Well, managing a project involves not only technical knowledge but also managing teams. And managing teams involve navigating human emotions. You need to be able to handle conflicts, inspire trust, communicate thoughts and ideas effectively, and handle pressure without losing your cool.&lt;/p&gt;

&lt;p&gt;Don't think EQ is essential for managing projects? Think of successful projects you've seen in the past. Were they solely successful due to technical factors, or was there a human factor involved too? Chances are, there was a skilled project manager who was in tune with the team's emotions, worked to resolve conflicts, and managed to bring everyone together to achieve success.&lt;/p&gt;

&lt;p&gt;But how can EQ be developed? Fortunately, as with any skill, this one can also be developed. The components of EQ include self-awareness, self-regulation, motivation, empathy, and social skills. By learning and practicing these components, you can build your EQ, enhancing your project management skills.&lt;/p&gt;

&lt;p&gt;Now that you understand what emotional intelligence is and why it's important let's take a deeper dive into the components of EQ, how you can develop it, and how you can use it to overcome challenges in project management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Emotional Intelligence
&lt;/h2&gt;

&lt;p&gt;We all have come across managers who have a high IQ and a proven track record but have struggled to lead and have a poor understanding of their team's emotions. That's why emotional intelligence has gained attention in recent years, particularly in project management.&lt;/p&gt;

&lt;p&gt;The concept of emotional intelligence was first developed in the 1970s and 80s, and later popularized by Daniel Goleman in his 1995 book on the topic. In this book, Goleman emphasizes the significance of EQ in leadership.&lt;/p&gt;

&lt;p&gt;In simple words, emotional intelligence is the ability to understand, regulate, and use emotions effectively in ourselves and others.&lt;/p&gt;

&lt;h3&gt;
  
  
  The four components of Emotional Intelligence
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmaz0z9hsfk263n7afrm5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmaz0z9hsfk263n7afrm5.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Self-awareness&lt;/strong&gt;: the ability to recognize and understand one's own emotions, including strengths, weaknesses, values, and goals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Self-management&lt;/strong&gt;: the ability to regulate emotions, control impulsivity, and adapt to changing circumstances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Social awareness&lt;/strong&gt;: understanding social and emotional cues, assessing team dynamics, and building relationships.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Relationship management&lt;/strong&gt;: the ability to communicate effectively, influence others positively, and resolve conflicts constructively.&lt;/p&gt;

&lt;p&gt;Assessing your emotional intelligence is essential to understand your EQ level. A simple and effective way to assess this is to take a self-assessment test. Several online tools are available to help gauge your EQ level, like the Emotional Quotient Inventory (EQi) and the Mayer-Salovey-Caruso Emotional Intelligence Test (MSCEIT), among others. Taking EQ assessments regularly helps track personal progress and identify areas that need further development.&lt;/p&gt;

&lt;p&gt;Developing emotional intelligence requires consistent effort, but the results are valuable. It's not about being emotional, but it's about understanding emotions and using them effectively.&lt;/p&gt;

&lt;p&gt;Building emotional intelligence skills is a personal journey that helps develop better relationships, improves communication, and leads to personal and professional growth. So, embrace the power of emotional intelligence and see the positive impact it can have in your personal and professional life.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Emotional Intelligence is Essential for Project Management
&lt;/h2&gt;

&lt;p&gt;Let's be honest, being a project manager is tough. You're responsible for ensuring that a project is successful, meeting deadlines, and keeping the team and all the stakeholders happy and motivated. It takes a lot of effort and skill to make all those pieces work together cohesively.&lt;/p&gt;

&lt;p&gt;Emotional intelligence is the secret ingredient that makes it all happen. EQ isn't something we're born with, it's a skill that can be developed over time. Leaders who possess EQ skills have an innate ability to empathize with others, be self-aware, and communicate effectively.&lt;/p&gt;

&lt;p&gt;When it comes to project management, the role of EQ is critical. For one, it allows project managers to be great leaders. They can connect with their team on a personal level, understand their individual strengths and weaknesses, and motivate them to do their best work. The result is a team that is fully invested in the project, which leads to greater success.&lt;/p&gt;

&lt;p&gt;EQ also ensures that projects are successful. When project managers possess strong EQ skills, they can effectively manage change and navigate stressful situations. They can tap into their own emotions, as well as the emotions of the team, to make decisions that lead to positive outcomes.&lt;/p&gt;

&lt;p&gt;EQ also influences team dynamics in incredible ways. When a project manager can build emotional connections with team members, they create a positive and supportive environment where everyone feels heard and valued. Communication is open, and team members feel comfortable sharing their thoughts and ideas. This leads to a work environment where people are more motivated to do their best work and are invested in the success of the project.&lt;/p&gt;

&lt;p&gt;As a project manager, conflicts among team members can be inevitable. However, having a high emotional intelligence will help de-escalate emotions during conflicts and achieve conflict resolution. Being emotionally intelligent means understanding your own emotions, as well as the emotions of those around you. When you are able to identify these emotions, you can communicate more effectively and prevent conflicts from escalating. It's important to actively listen to understand both sides of the situation and find a solution that works for everyone. By utilizing your EQ skills and practicing conflict resolution techniques, you can create a positive and productive work environment for your team.&lt;/p&gt;

&lt;p&gt;If you want to be a successful project manager, developing your EQ skills should be at the top of your to-do list. It's not enough to just manage deadlines and budgets; a truly great leader takes the time to connect with their team on an emotional level, brainstorm ideas and solutions with them, and motivate them to succeed. With EQ skills, you can become the project manager that your team loves to work with and one that produces outstanding results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Developing Emotional Intelligence as a Project Manager
&lt;/h2&gt;

&lt;p&gt;Now that we have a clear understanding of what emotional intelligence is and why it’s so vital for project management, let's explore how you can develop your own emotional intelligence as a project manager.&lt;/p&gt;

&lt;h3&gt;
  
  
  Identifying and Managing Your Own Emotions:
&lt;/h3&gt;

&lt;p&gt;The first step in developing your emotional intelligence is to become more aware of your own emotions and how they impact your decision-making process. This requires a great deal of self-reflection, which can be uncomfortable at times. However, it is essential to be aware of our emotions and the impact they have on our behavior.&lt;/p&gt;

&lt;p&gt;One way to become more emotionally self-aware is to regularly reflect on how you feel, especially when experiencing strong emotions. Take a few deep breaths, pause, and acknowledge your emotions. Then, try to name what you are feeling and consider how it might be affecting your behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recognizing Emotions in Others:
&lt;/h3&gt;

&lt;p&gt;Once you have a better understanding of your own emotions, the next step is to develop your ability to pick up on other people's emotions. This involves being attuned to the verbal and non-verbal cues that people give off and putting yourself in their shoes to get a sense of how they might be feeling.&lt;/p&gt;

&lt;p&gt;You can practice active listening to improve your ability to pick up on other people's emotions. This means giving your full attention to the person speaking, focusing on their body language, tone, and pauses, and asking clarifying questions to ensure that you understand what they are saying.&lt;/p&gt;

&lt;h3&gt;
  
  
  Communicating Effectively with Team Members:
&lt;/h3&gt;

&lt;p&gt;Communicating effectively is crucial in project management, and emotional intelligence plays a vital role in how you deliver your message. It's important to be aware of your tone, facial expressions, and body language when communicating with team members. They can either positively or negatively impact the team's morale.&lt;/p&gt;

&lt;p&gt;To enhance your communication skills, start by practicing active listening. Then try to articulate your thoughts and feelings clearly and concisely while also making an effort to understand the other person's perspective. It's important to be aware that everyone is different and has different communication styles; be patient and willing to adapt.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building Relationships with Team Members:
&lt;/h3&gt;

&lt;p&gt;Building strong relationships with team members is essential to effective project management. It's easier to work together when team members trust and respect one another.&lt;/p&gt;

&lt;p&gt;To build relationships with team members, start by empathizing with them. Take the time to get to know each person on your team as an individual. Learn their strengths and weaknesses, interests, and hobbies. Then, try to find ways to connect with each team member, such as sharing personal stories or jokes. Doing so will help to build trust and establish rapport.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resolving Conflicts using Emotional Intelligence:
&lt;/h3&gt;

&lt;p&gt;Conflicts are inevitable in any project, and managing them effectively is crucial to success. Emotionally intelligent project managers can handle conflicts by understanding how to manage their own emotions and how to handle difficult conversations.&lt;/p&gt;

&lt;p&gt;To resolve conflicts using emotional intelligence, aim to take a collaborative approach. Start by acknowledging the concerns of all parties involved and work together to find a compromise that meets everyone's needs. Focus on shared goals, and remain open and non-judgmental throughout the process. Ultimately, the key to success lies in being willing to listen and having a willingness to find common ground.&lt;/p&gt;

&lt;p&gt;Developing your emotional intelligence takes time and effort, but the rewards in terms of improved leadership, team dynamics, and project success are worth it. By becoming more self-aware, empathetic, and effective communicators, project managers can lead their teams to success while nurturing positive work relationships.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges to Developing Emotional Intelligence as a Project Manager
&lt;/h2&gt;

&lt;p&gt;Managing a project requires a significant level of emotional intelligence. However, developing EQ poses several challenges for project managers. One of the greatest hurdles is the impact of culture and diversity in managing a team. Different cultures and experiences shape how we think, communicate, and identify emotions. Language barriers may also hinder effective communication leading to misunderstandings.&lt;/p&gt;

&lt;p&gt;To overcome this, project managers must adopt an inclusive approach that embraces diversity and promotes a culture of understanding. They should establish clear communication channels and tailor their management style to suit the team's needs. Encouraging open communication and listening actively to the team's input is crucial in managing diversity effectively.&lt;/p&gt;

&lt;p&gt;Another challenge is managing personal biases, as they impede objective decision-making. Personal biases are inherent and are influenced by an individual's upbringing, self-awareness, and interactions with others. Project managers must identify and acknowledge their biases to avoid letting them cloud their judgment. One way to achieve this is by taking personality tests to gain insights into their behavior and thought patterns.&lt;/p&gt;

&lt;p&gt;Balancing emotion with rationality is also essential. While EQ advocates for managing emotions, it also emphasizes critical thinking and logical reasoning. Emotional outbursts may be detrimental to project management if decisions are made based on emotions rather than facts. Thus, project managers should take time to assess situations and make calculated decisions.&lt;/p&gt;

&lt;p&gt;To sum up, developing emotional intelligence is challenging but critical for effective project management. By adopting an inclusive approach, identifying biases, and taking the time to make logical decisions, project managers can build a culture that values and promotes emotional intelligence.&lt;/p&gt;

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

&lt;p&gt;Congratulations! You’ve made it to the end of this post – a true testament to your emotional intelligence.&lt;/p&gt;

&lt;p&gt;I hope this post has helped you understand the importance of emotional intelligence in project management and how honing these skills can lead to personal and professional growth.&lt;/p&gt;

&lt;p&gt;Remember, emotional intelligence isn’t just about being touchy-feely - it’s about being able to manage your emotions and the emotions of those around you effectively. When you can do that, you’ll be better equipped to lead a successful project and navigate any challenges that come your way.&lt;/p&gt;

&lt;p&gt;Don’t forget, building your emotional intelligence is a journey, and like any journey, it comes with its fair share of challenges and roadblocks. But with the right mindset and determination, you can overcome them and achieve great things.&lt;/p&gt;

&lt;p&gt;Thanks for reading, and remember, success is not just about what you know; it’s also about how well you can manage yourself and others.&lt;/p&gt;

</description>
      <category>pm</category>
      <category>eq</category>
      <category>ei</category>
      <category>projects</category>
    </item>
    <item>
      <title>Don't Delay: A Guide to Overcoming Procrastination</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Mon, 30 Jan 2023 05:31:34 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/dont-delay-a-guide-to-overcoming-procrastination-3fmh</link>
      <guid>https://dev.to/sumusiriwardana/dont-delay-a-guide-to-overcoming-procrastination-3fmh</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"&lt;strong&gt;Procrastination is like a credit card: it's a lot of fun until you get the bill.&lt;/strong&gt;"&lt;br&gt;&lt;br&gt;
- Christopher Parker&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When I was younger, especially in school, I used to loathe preparing for exams. So even though I prepared a study plan, I never picked up the study materials when the time came. Instead, I used to tell myself, "I will read this novel for 10 minutes and then start studying." But that study time never happened. Sometimes, my mother checked on me to see whether I was studying, and I hid my novel inside the textbook and pretended I was reading the textbook.&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%2Fmedia3.giphy.com%2Fmedia%2F3ornkbzy8iuqCmi9lS%2Fgiphy.gif%3Fcid%3D790b761167b72c49959287bd54474c7db0ae08798e30f0a3%26rid%3Dgiphy.gif%26ct%3Dg%2520align%3D" 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%2Fmedia3.giphy.com%2Fmedia%2F3ornkbzy8iuqCmi9lS%2Fgiphy.gif%3Fcid%3D790b761167b72c49959287bd54474c7db0ae08798e30f0a3%26rid%3Dgiphy.gif%26ct%3Dg%2520align%3D" alt="Read Joan Fontaine GIF by Warner Archive"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I postponed my study time until a few days left for the exam and then rushed through my notes, trying to remember everything quickly. By the time I faced the exam, I was stressed, tired, and sleep deprived, which always led to having average marks for each paper. Each time this happened, I promised myself to stick to the study plan next time. But when the time came, I always ended up doing the same thing.&lt;/p&gt;

&lt;p&gt;After a few years, I took accounting as a subject and realized I loved balancing sheets. So every day, I took a problem and worked on it. In a very short time, I became good at accounting. Then I combined this love of solving account problems with other subjects. For example, I promised myself that if I covered one economic concept, I would allow myself to work on an accounting problem. This helped me overcome my problem of studying, and I could score good marks during my &lt;a href="https://en.wikipedia.org/wiki/GCE_Advanced_Level_in_Sri_Lanka" rel="noopener noreferrer"&gt;A/Ls.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I started using this method whenever I got stuck with procrastination over the years. Sometimes it worked very well. But in some cases, my will to enjoy short-term satisfaction was stronger than focusing on the long-term goal or the benefit. Especially when I wanted to start a workout routine and start learning to program. So I started reading and researching how to stop procrastinating, stick to a schedule, and get things done.&lt;/p&gt;

&lt;p&gt;Over the years, I came across some handy methods and tips which really helped me overcome this issue. Of course, there are lousy days once in a while, but my procrastinating problem has been reduced by 90%-95%.&lt;/p&gt;

&lt;p&gt;If you are someone like me, who's a master of procrastinating, this article is for you to understand what procrastination is and how to overcome it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is procrastination
&lt;/h2&gt;

&lt;p&gt;Procrastination is delaying or putting off things until the last minute or even after their deadline. The word &lt;em&gt;"procrastinate"&lt;/em&gt; originates from Latin, which means &lt;strong&gt;&lt;em&gt;‘deferred till the morning’&lt;/em&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;em&gt;‘belonging to tomorrow’&lt;/em&gt;&lt;/strong&gt;.&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%2Fuploads%2Farticles%2Fsnsjz4fdoz93so2vaywq.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%2Fuploads%2Farticles%2Fsnsjz4fdoz93so2vaywq.png" alt="origin of the word procrastinate"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At least once in our life, we have procrastinated on at least one task. This is a common thing among human beings. We sometimes delay taking action on a specific task, postpone dreadful appointments, and even avoid having stressful conversations.&lt;/p&gt;

&lt;p&gt;While procrastinating here and there might not cause significant harm in achieving your goals, it could crush your goals and dreams or even cost your jobs if it becomes a habit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identify your procrastination triggers
&lt;/h2&gt;

&lt;p&gt;Procrastination is a common behavior, and it's not the problem. Instead, procrastination is a symptom of underlying issues, such as perfectionism, a lack of motivation, feeling overwhelmed or overconfident, or fear of failure.&lt;/p&gt;

&lt;p&gt;And these problems could occur due to mental health, &lt;a href="https://www.nhs.uk/conditions/attention-deficit-hyperactivity-disorder-adhd/" rel="noopener noreferrer"&gt;ADHD&lt;/a&gt;, and personality traits such as low self-efficacy, Impulsivity, or low conscientiousness.&lt;/p&gt;

&lt;p&gt;Identifying the trigger points of procrastination will help you to understand why you are doing it and allow you to take action to overcome it. Let's look at some common procrastination triggers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fear of failure:&lt;/strong&gt; the fear of not being able to complete a task or doing it poorly can cause procrastination.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Perfectionism:&lt;/strong&gt; it can be hard to start or finish things when you're trying to be perfect.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lack of motivation:&lt;/strong&gt; if you don't have a clear goal or intrinsic motivation, it can be hard to start something.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Distractions:&lt;/strong&gt; getting distracted by social media, video games, or constant interruptions can be tough and make it difficult for you to focus on a task.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Boredom:&lt;/strong&gt; if a task is tedious or unexciting, you might find it hard to summon the energy to do it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decision fatigue:&lt;/strong&gt; when you make too many decisions, your brain gets tired, so it's hard to get started.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Overwhelm:&lt;/strong&gt; you might feel overwhelmed by the size or complexity of the task, making it hard for you to begin.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Procrastination itself:&lt;/strong&gt; procrastinating on one task can lead to procrastinating on other tasks, creating a cycle of delay.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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%2Fuploads%2Farticles%2F144aerb4fhmut31sskm9.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%2Fuploads%2Farticles%2F144aerb4fhmut31sskm9.png" alt="quote about fear of failure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can analyze your emotions and understand why, when, and how you procrastinate. The first step in overcoming procrastination is identifying your trigger points. It always helps to be aware of the problem to overcome it. Then the tips below can help you develop a plan to make progress and stay on task.&lt;/p&gt;

&lt;h2&gt;
  
  
  5 Tips to overcome procrastination
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Set small goals which can be achievable
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Break down tasks into smaller chunks
&lt;/h4&gt;

&lt;p&gt;Often you get overwhelmed when the task at hand is too big or the scope of the long-term goal seems much more significant. When you break down these big tasks and goals into achievable chunks, it's easier for you to focus on one part at a time and progress toward the end.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Want to lose weight? First, break down the goal into tasks that you have to do in order to achieve it. Then break down the exercises you want to do for each day. For example, Monday-Cardio, Tuesday-Leg Day, etc. When you break it down to the type of exercise you want to do each day, you have a clear idea of what you have to achieve each day without getting overwhelmed by the end goal of the workout.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Want to start learning web development? Break down the roadmap into subgoals with relevant resources. For example, you can make the first sub-goal learning HTML. Then, you can further break it into topics, such as learning &lt;code&gt;&amp;lt;!DOCTYPE&amp;gt;&lt;/code&gt; declaration, basic HTML tags, etc. Now you have a clear idea about smaller topics you have to learn each day or time.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Similarly, you can list down all the items you must complete the next day at the end of each day. While doing this, you can identify big tasks and break them into smaller chunks. Now you have a clear idea of what you want to complete tomorrow that is more achievable.&lt;/p&gt;

&lt;h4&gt;
  
  
  2-minute rule
&lt;/h4&gt;

&lt;p&gt;If you already have the breakdown and you are still hesitant to start, you can start following the &lt;a href="https://jamesclear.com/how-to-stop-procrastinating" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;"2-minute rule"&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;. David Allen inspires the 2-minute rule: &lt;em&gt;"If it takes less than two minutes, then do it now.”&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When you want to exercise daily, &lt;strong&gt;make your only goal to put on your workout shoes.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you want to learn a new programming language, &lt;strong&gt;make your only goal to write one line of code.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you want to start reading daily, &lt;strong&gt;make your only goal to&lt;/strong&gt; &lt;strong&gt;read one page&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you want to write daily, &lt;strong&gt;make your only goal to&lt;/strong&gt; &lt;strong&gt;write one sentence.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The idea behind this is to make your tasks easier to start. For example, working out for one hour might seem tedious. Or you might even feel lazy thinking about that hour. But putting on your workout shoes is an effortless task, and once you've put them on, you would instead start your workout than remove your shoes. Once you start, it's easier to keep the momentum and continue the task.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Organize your tasks
&lt;/h3&gt;

&lt;p&gt;When you don't have a schedule or an agenda for a day or specific time, it's easier for your mind to forget what needs to be done, or procrastinate, thinking you still have time to achieve your tasks.&lt;/p&gt;

&lt;p&gt;Once you break down your tasks, you can prioritize each and set a day to complete them. And create a schedule for each day, including specific times for different tasks. For example, if you are more productive in the early hours of the day, you can schedule your writing and learning during this time. If you have more physical energy than mental energy in the morning, you can plan your workout in the morning.&lt;/p&gt;

&lt;p&gt;Creating a rhythm of "I'm going to do X now, and then I will do Y " each day by organizing your tasks helps you mentally prepare for each focus time, make it easier to move through your tasks, and build and maintain discipline.&lt;/p&gt;

&lt;p&gt;Organizing your tasks with clear deadlines and a schedule to complete them can keep you motivated to achieve your main goal. Remember to include break times and keep a buffer for unexpected events in your schedule, so you don't get overwhelmed when things change.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Remove Distractions
&lt;/h3&gt;

&lt;p&gt;It's harder to get things done or focus on specific tasks when you constantly get distracted or interrupted. So identify your distraction points and try eliminating them as much as possible.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you tend to check your phone all the time and get distracted from social media and messages, put your phone into airplane mode, turn off your internet, or set up focus modes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Block your calendar for the focus time, so no one schedules ad-hoc meetings without checking up with you.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If your current environment distracts you, find a quiet space to focus.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Snooze your work email and chat, or put your status as "Do not disturb".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Try to work on full screen on your computer so that you don't get distracted from other things (Especially from those 100 tabs you have already opened, including the social media sites 😉)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clear your desk and remove all the unnecessary things and tempting distraction points such as books, phones, etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Focus your attention
&lt;/h3&gt;

&lt;p&gt;Even after removing all the distractions, you might find it hard to focus on the current task. Sometimes you would feel like checking the phone, or you might think about the bigger task you have to do next.&lt;/p&gt;

&lt;h4&gt;
  
  
  Choose cakewalk or Eat that frog
&lt;/h4&gt;

&lt;p&gt;You can focus on smaller and more manageable tasks to complete at first if you want to build momentum and motivate yourself to accomplish more within the day. But if you are a person who constantly stresses about big or more complex tasks, get rid of that stress by doing the biggest/hardest task first (&lt;a href="https://www.briantracy.com/blog/time-management/the-truth-about-frogs/" rel="noopener noreferrer"&gt;eat that frog!&lt;/a&gt;)&lt;/p&gt;

&lt;h4&gt;
  
  
  Positive Rituals
&lt;/h4&gt;

&lt;p&gt;You can also start creating positive rituals to prepare yourself for the focus mode. Have you seen sports stars doing some activities before they start playing? How are soldiers preparing for combat? These activities make them make decisions automatically and get into their focus mode.&lt;/p&gt;

&lt;p&gt;You can clean your desk or count to 5 before you start your task. Or find a positive ritual that helps you to give your brain the signal of "it's time to focus!"&lt;/p&gt;

&lt;h4&gt;
  
  
  Set a timer or use the Pomodoro technique
&lt;/h4&gt;

&lt;p&gt;If you have set your task for a specific period (Ex: Read for 30min, code for 30 min), set a timer for that time and work on one task until the timer goes off. During this time, you can focus on the task without checking the clock from time to time and move on to the other task after a break. You can use the &lt;a href="https://www.lifehack.org/articles/productivity/the-pomodoro-technique-is-it-right-for-you.html" rel="noopener noreferrer"&gt;Pomodoro&lt;/a&gt; technique to organize and manage your focus times.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Reward Yourself
&lt;/h3&gt;

&lt;p&gt;Giving yourself a small reward after completing a task can be a great way to stay motivated and avoid procrastination. Find tempting rewards that can motivate you so that you tend to complete the task to get your bonus. You can use different reward systems to combine with your tasks.&lt;/p&gt;

&lt;h4&gt;
  
  
  If-then rewarding
&lt;/h4&gt;

&lt;p&gt;Plan your tasks with the if-then intention, in which you reward yourself by doing something you really like (such as hobbies, favorite food, etc.) after completing a task.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;If&lt;/strong&gt; I complete this programming topic, &lt;strong&gt;then&lt;/strong&gt; I will allow myself to play a game for 30 mins.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;If&lt;/strong&gt; I complete the essay, &lt;strong&gt;then&lt;/strong&gt; I will allow myself to read one chapter from the new novel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;If&lt;/strong&gt; I complete two tasks, &lt;strong&gt;then&lt;/strong&gt; I will allow myself to watch TikTok/Reels for 5 minutes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will help you to create excitement to finish your task so that you can reward yourself with your hobbies and guilty pleasures.&lt;/p&gt;

&lt;h4&gt;
  
  
  Temptation Bundling
&lt;/h4&gt;

&lt;p&gt;Another technique you can use is &lt;a href="https://www.mayooshin.com/temptation-bundling" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;"Temptation Bundling"&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;. Temptation bundling combines an activity you procrastinate on with an activity you like to do.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You could watch a TV/movie &lt;strong&gt;only&lt;/strong&gt; while you are using the treadmill.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You could listen to podcasts/audiobooks &lt;strong&gt;only&lt;/strong&gt; while you are coding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can listen to music &lt;strong&gt;only&lt;/strong&gt; when you are at the gym.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Temptation bundling will help you complete your tasks delightfully and build healthier habits by combining your favorite activities or guilty pleasures.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus tip: Forgive yourself
&lt;/h3&gt;

&lt;p&gt;Overcoming procrastination takes time and discipline. Don't beat yourself too hard if you fail to meet your goals. Punishing yourself for being too lazy or worrying about being unproductive will increase your anxiety, stress, and frustration, making you even more unproductive with those negative thoughts.&lt;/p&gt;

&lt;p&gt;Be kind to yourself and learn what mistakes you made and why you made that decision/took that action. And adjust your techniques each time when you fail. Finally, remember never to give up and start over and over again with self-compassion until you reach your goals.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Bottom Line&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Procrastination is a common human behavior. The first step toward overcoming procrastination is understanding its cause and trigger points. You can start understanding this by writing down the goals/tasks you should do and how, when, and why you’ve been procrastinating on them.&lt;/p&gt;

&lt;p&gt;Next, you can use some of the tips and anti-procrastination techniques mentioned here that might help in your situation and start implementing them.&lt;/p&gt;

&lt;p&gt;Remember, you don't have to overcome this on the first try. If something doesn't work, experiment with some other technique. There are numerous kinds of research on this topic where you can find more tips and techniques. If you still feel like you are struggling, you can always seek help from coaches, therapists, and friends.&lt;/p&gt;

&lt;p&gt;The most important factor is &lt;strong&gt;"start now, don't wait till tomorrow!"&lt;/strong&gt;&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%2Fuploads%2Farticles%2F2bmwx7qjywer6r22yb7a.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%2Fuploads%2Farticles%2F2bmwx7qjywer6r22yb7a.png" alt="Quote about start now"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;I hope this post helps you understand the causes of procrastination and how you can use some anti-procrastination techniques to overcome it. If you have any more things to add to these tips and techniques, I would love to hear from you 😊&lt;/p&gt;

&lt;p&gt;Feel free to connect with me on &lt;a href="https://twitter.com/sumusiriwardana" rel="noopener noreferrer"&gt;&lt;strong&gt;Twitter&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/sumudusiriwardana/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>productivity</category>
    </item>
    <item>
      <title>How to Leverage Being an Introvert for Better Content Creation</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Mon, 24 Jan 2022 02:54:01 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/how-to-leverage-being-an-introvert-for-better-content-creation-3mnm</link>
      <guid>https://dev.to/sumusiriwardana/how-to-leverage-being-an-introvert-for-better-content-creation-3mnm</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“Introverts don’t shout at the world, they listen!”&lt;br&gt;
-Jayne Thompson.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The day I learned the word “introvert”, I finally understood myself completely. I had spent my entire day reading, researching, and taking every test on introversion. Finally, I understood why I don't fit in with most of my friends, why I enjoy my own company most of the time, and there is nothing wrong with me. &lt;/p&gt;

&lt;p&gt;I grew up in a "culture of personality" where everything is designed to cater to extroverts. For example, we were always encouraged and rewarded for working together, speaking up, or asking questions in schools. Likewise, we were promoted and rewarded for marketing ourselves with outgoing personalities at workplaces. Sometimes, we had to pretend to be extroverts in order to fit into the system. &lt;/p&gt;

&lt;p&gt;Technology and this digital age have empowered introverts to thrive and connect with everyone on their own terms. This is becoming a golden age for us to connect, share, and help others with different communication options while living in our own quiet mind, choosing our own terms. This is why introverts are thriving in content creation. The unique characteristics of introversion help us capture our audience with authentic and insightful content.&lt;/p&gt;

&lt;p&gt;I recently had a very interesting session with &lt;a href="https://twitter.com/FrancescoCiull4" rel="noopener noreferrer"&gt;Francesco Ciulla&lt;/a&gt; about &lt;a href="https://www.youtube.com/watch?v=zUwB_imVjmg" rel="noopener noreferrer"&gt;introverts and content creations&lt;/a&gt;. During this session, one of the questions that came up was, &lt;strong&gt;being an introvert makes us better at content creation or not&lt;/strong&gt;. So let's dive into some of the unique strengths that help introverts excel in content creation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introverts are good listeners
&lt;/h2&gt;

&lt;p&gt;We introverts always prefer to listen more than talk. We only voice our opinion when it's necessary. But, unfortunately, most of the time, most people never truly listen anymore. Instead, they wait to react immediately or voice their opinion. &lt;/p&gt;

&lt;p&gt;When we listen to our audience deeply, we can genuinely understand their needs and problems. As a result, we'll be more empathetic and closer to their minds. This helps us customize our content with different perspectives providing multiple solutions for their problems. &lt;/p&gt;

&lt;p&gt;The same way you listen in real life, start listening to conversations on the internet. Find the social media platforms, forums, content platforms where your relevant topics are popular and observe the discussions. This could be Twitter, Reddit, Instagram, TikTok, or any other platform that you frequently visit. And use your superpowers of listening and observing skills to notice the things that others might not notice. &lt;/p&gt;

&lt;p&gt;Once you patiently listen and understand each perspective, you can develop a solution for these problems and share. When your audience realizes that you listen to them and provide solutions for their problems, they start trusting you. &lt;/p&gt;

&lt;h2&gt;
  
  
  Introverts get straight to the point
&lt;/h2&gt;

&lt;p&gt;We introverts hate small talk so much and unnecessary details. So we always find ways to authentically communicate and hold attention throughout the stories that we share. &lt;/p&gt;

&lt;p&gt;In today's world, everyone has a very short attention span. Reading through long paragraphs or listing to endless details will quickly discourage someone from reading our articles or listening to our podcasts. &lt;/p&gt;

&lt;p&gt;Use this superpower to structure your content with creative yet straightforward language that your audience will not have to spend much time to get to the important points and a summary of your message that you want to communicate. &lt;/p&gt;

&lt;h2&gt;
  
  
  Introverts love helping others
&lt;/h2&gt;

&lt;p&gt;Since we are deep listeners and more empathetic, we tend to help others. This makes us want to share our knowledge with others and help them genuinely. &lt;/p&gt;

&lt;p&gt;Professionally or personally, you can create authentic and valuable content for your audience to share your knowledge and help them rather than providing redundant content for the sake of content creations. &lt;/p&gt;

&lt;p&gt;For us, it's not about clickbait. It's about the real value that we add to our content to help someone! &lt;/p&gt;

&lt;p&gt;Don't be shy or scared to share your thoughts if you think that you can help someone with even a small word. Your readers will appreciate your support. But think twice whether you are adding real value to your content. If you really want to help, the value matters. &lt;/p&gt;

&lt;h2&gt;
  
  
  Introverts don't want to be in the spotlight
&lt;/h2&gt;

&lt;p&gt;As introverts, we never care about being in the spotlight. Instead, we give credit to our teams or shift the attention to our work. &lt;/p&gt;

&lt;p&gt;So when we create content, we never shift the focus to ourselves. This helps us win the trust of our audience and make them listen to us. &lt;/p&gt;

&lt;p&gt;Be more mindful when you are creating content. Always think about the purpose and the audience when you are creating content. The more you understand your audience and the purpose, the easier it is to shift the focus and truly serve the purpose of their needs. &lt;/p&gt;

&lt;p&gt;If you use storytelling as your content strategy, avoid gold plating and be authentic. Shift the focus of your story for your audience's need rather than highlighting yourself or the product too much. &lt;/p&gt;

&lt;h2&gt;
  
  
  Introverts take time to react
&lt;/h2&gt;

&lt;p&gt;As introverts, we like to process information before reacting to anything asap. So we usually don't react to any comments fast without processing the data and having a solid answer. This helps us to win our audience's trust in our knowledge. &lt;/p&gt;

&lt;p&gt;Also, this quality is beneficial when dealing with critics and negativity. We can take time to process our feeling and thoughts carefully and decide whether to react or not. &lt;/p&gt;

&lt;p&gt;Introvert or not, sometimes you can be very sensitive, but when you come across negativity and trolls, it's better to avoid engagement and not take it personally. &lt;/p&gt;

&lt;h2&gt;
  
  
  Introverts enjoy solitude
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Without great solitude, no serious work is possible - Pablo Picasso&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For us introverts, solitude is the source of our energy and quality work! &lt;/p&gt;

&lt;p&gt;We get our most creative ideas, think deeply, and be our authentic selves when we are alone and away from the noisy world. &lt;/p&gt;

&lt;p&gt;It's important to listen to your readers and understand them, but when you create and present your content, you need to have your own opinion and be authentic to win their trust. &lt;/p&gt;

&lt;p&gt;This means understanding yourself, what you believe in, what you stand for. This is the time we can use to understand ourselves, connect with our minds, and find our authentic voice. &lt;/p&gt;

&lt;p&gt;Dedicate this time in your calendar for deep thinking and content creation so that you will start using this time as a habit. It will help you avoid procrastination and be consistent with your content creations. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1642940197381%2FHbOS19JBC.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1642940197381%2FHbOS19JBC.jpeg" alt="photo-1504805572947-34fad45aed93.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@clarktibbs" rel="noopener noreferrer"&gt;Clark Tibbs&lt;/a&gt; from &lt;a href="https://unsplash.com/photos/oqStl2L5oxI" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Technology has empowered us introverts and facilitated new communication platforms to thrive with our unique strengths. Now it's time for us to understand our strengths, leverage them to create better content, and thrive as content creators! &lt;/p&gt;

&lt;p&gt;I hope this post helps you understand your own strengths and how to use them to create better content.  If you have any more things to add to these qualities, I would love to hear from you 😊&lt;/p&gt;

&lt;p&gt;Feel free to connect with me on &lt;a href="https://twitter.com/sumusiriwardana" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/sumudusiriwardana/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>writing</category>
      <category>motivation</category>
    </item>
    <item>
      <title>What is Scope and Scope Chain in JavaScript?</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Wed, 22 Dec 2021 08:55:08 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/what-is-scope-and-scope-chain-in-javascript-52j5</link>
      <guid>https://dev.to/sumusiriwardana/what-is-scope-and-scope-chain-in-javascript-52j5</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article was originally published on &lt;a href="https://dasha.ai/en-us/blog/javascript-scope-and-scope-chain" rel="noopener noreferrer"&gt;Dasha.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In case you are wondering, Dasha is a &lt;strong&gt;conversational-AI-as-a-service&lt;/strong&gt; platform that lets you embed realistic voice and text conversational capabilities into your apps or products.  &lt;a href="https://auth.dasha.ai/account/register" rel="noopener noreferrer"&gt;Start building for free!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;The scope and scope chain are fundamental concepts in JavaScript and other programming languages. Also, one of the most confusing concepts at the beginning. Understanding the scope and scope chain is crucial for writing efficient, clean code and essential to building a solid foundation and mastering JavaScript. &lt;/p&gt;

&lt;p&gt;If you are new to JavaScript, you might be struggling to understand these concepts. I remember how long it took me to get a firm understanding of these two tricky concepts. In this post, we will go through the scope and scope chain with some simple examples to clear out the confusion. &lt;/p&gt;

&lt;p&gt;Without further ado, let's get started 😊&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1639934075242%2FjBTOnq_-z.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1639934075242%2FjBTOnq_-z.gif" alt="right.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Scope?
&lt;/h2&gt;

&lt;p&gt;Have you ever wondered why you can't access some of the variables outside a function? Or did you find it strange that you can have the same variable name outside a function and inside a function as well? The reason for this strange behavior is that every variable, function, or code block has its own scope. &lt;/p&gt;

&lt;p&gt;According to  &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Scope" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;, the scope is,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The current context of execution. The context in which values and expressions are "visible" or can be referenced. If a variable or other expression is not "in the current scope," then it is unavailable for use.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What does this mean?&lt;/p&gt;

&lt;p&gt;Scope in JavaScript refers to the accessibility or visibility of variables and expressions. That means the space where an item, such as a variable or a function, is visible and accessible in your code. &lt;/p&gt;

&lt;p&gt;For example, once a variable is declared, it can only be accessible within the scope that it has been declared in and will not be accessible outside the scope.&lt;/p&gt;

&lt;p&gt;Let's look at a couple of examples to understand this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sarah&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// "Sarah"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have declared a variable &lt;code&gt;userName&lt;/code&gt; and assigned the value of &lt;code&gt;Sarah&lt;/code&gt;. No issue or error is coming up when we want to access this variable and print the name to the console. &lt;/p&gt;

&lt;p&gt;Now let's declare this variable inside a function and print the value to the console outside the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sarah&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "Hello Sarah!"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: userName is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, when trying to log the variable, JavaScript throws an error, &lt;code&gt;ReferenceError: userName is not defined&lt;/code&gt;. This is because the &lt;code&gt;greeting&lt;/code&gt; function creates a scope for the &lt;code&gt;userName&lt;/code&gt; variable. And the &lt;code&gt;userName&lt;/code&gt; variable can be accessed only within this scope, inside the function.&lt;/p&gt;

&lt;p&gt;You might think that this behavior is strange. But having a scope for variables and expressions helps us to write efficient code and avoid conflicts and errors within our code. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why is Scope important?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Ownership
&lt;/h4&gt;

&lt;p&gt;One of the main benefits of scope is ownership. If we can access all variables from anywhere within our program, it will lead to unintended modifications to the variable from other parts of the program. Which means anyone can change them from anywhere at any given time.&lt;/p&gt;

&lt;p&gt;With scoping, we can only access the variables in a certain area of the code. The scope helps to avoid these modifications, which help us to write secure code. &lt;/p&gt;

&lt;h4&gt;
  
  
  2. Avoid name collision
&lt;/h4&gt;

&lt;p&gt;The scope helps to avoid name collision. For example, imagine that you have to use the same variable name in a different place in your program for a different purpose, or someone else from your team has already declared a variable in the global scope, and you want to identify the boundary of this variable. &lt;/p&gt;

&lt;p&gt;Having clear scope on where you can access a variable makes it easier to identify its boundary, avoid assigning more values to the same variable, and use the same variable name in multiple locations within the code without altering the values.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Garbage Collection
&lt;/h4&gt;

&lt;p&gt;In dynamic languages like JavaScript, when we complete the usage of a variable, the data will be automatically  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management" rel="noopener noreferrer"&gt;garbage collected&lt;/a&gt;. If we don't have a clear scope on where we can access certain variables, the compiler will not be able to identify when to collect the garbage, except at the end. &lt;/p&gt;

&lt;p&gt;Having a clear scope on where variables can be accessed helps the compiler to garbage collect these variables at the end of each scope.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Scope
&lt;/h2&gt;

&lt;p&gt;JavaScript has three different types of scope. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Global Scope&lt;/li&gt;
&lt;li&gt;Function Scope &lt;/li&gt;
&lt;li&gt;Block scope&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's take a few examples to understand these three different scopes. &lt;/p&gt;

&lt;h3&gt;
  
  
  Global Scope
&lt;/h3&gt;

&lt;p&gt;Variables declared outside of functions or code blocks (curly braces &lt;code&gt;{ }&lt;/code&gt;) are considered to have a global scope. The outermost scope contains the entire code, and there is only one global scope in the program. &lt;/p&gt;

&lt;p&gt;The variables defined in the global scope are named &lt;em&gt;Global Variables&lt;/em&gt; and can be accessed and altered in any other scopes. &lt;/p&gt;

&lt;p&gt;Check the below example. The function &lt;code&gt;greeting&lt;/code&gt; can access the &lt;code&gt;userName&lt;/code&gt; variable inside the function, and it is located in the global scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a variable in the global scope&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sarah&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Access global variable within the function&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// "Hello Sarah!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have the accessibility to change the value of the variable anywhere in the code with global scope. Check the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a global variable&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sarah&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Assigne a different value to the global variable&lt;/span&gt;
  &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jessica&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "Hello Jessica!"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Jessica"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have reassigned the value of the variable &lt;code&gt;userName&lt;/code&gt; inside the function. And it has modified the value of the variable inside the global scope. &lt;/p&gt;

&lt;p&gt;This means that we can alter global variables anywhere within our code. Therefore, it is advised to only use global variables if and only if necessary as a best practice. &lt;/p&gt;

&lt;p&gt;Let's move on to the function scope.&lt;/p&gt;

&lt;h3&gt;
  
  
  Function Scope
&lt;/h3&gt;

&lt;p&gt;Each and every function creates its own scope. And the variables declared inside that function are only accessible inside that function and any of its nested functions. This is also called &lt;em&gt;Local Scope&lt;/em&gt;.   &lt;/p&gt;

&lt;p&gt;Check the below examples to understand the function scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;birthyear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Declare variables inside the calcAge function scope&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;birthyear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1975&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Attempt to access "currentYear" and "age" outside of the function scope is not possible&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentYear&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: currentYear is not defined&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: age is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have a function to calculate the age. However, when trying to print the variables  &lt;code&gt;currentYear&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt;, JavaScript throws an error &lt;code&gt;ReferenceError: currentYear is not defined&lt;/code&gt;. This is because the &lt;code&gt;calcAge()&lt;/code&gt; function creates a scope for these variables, which can only be accessed within the function scope. &lt;/p&gt;

&lt;p&gt;I hope now you can understand how the function scope works. Let's move on to block scope. &lt;/p&gt;

&lt;h3&gt;
  
  
  Block Scope
&lt;/h3&gt;

&lt;p&gt;ES6 introduced &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; variables. With that, it introduced the block scope. Block scope means that the variables defined inside a code clock &lt;code&gt;{}&lt;/code&gt; can only be used inside it. &lt;/p&gt;

&lt;p&gt;For example, a variable created inside an &lt;code&gt;if&lt;/code&gt; statement or &lt;code&gt;for&lt;/code&gt; loop can only be accessed within that code block. Same as function scope, it is not accessible outside of the block scope. &lt;/p&gt;

&lt;p&gt;While &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are block scoped, the variables defined with &lt;code&gt;var&lt;/code&gt; have their scope limited to the current function scope or the global scope. Suppose we declare a variable using &lt;code&gt;var&lt;/code&gt;, that variable is accessible outside the block. So, the variable declared using &lt;code&gt;var&lt;/code&gt; within a code block is not block scoped; It is function scoped. &lt;/p&gt;

&lt;p&gt;Check the below example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;birthyear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;birthyear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a variable using "var" inside the block&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;working&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a variable using "const" inside the block&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Peter is still employed!`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Variable created using "var" can be accessed outside the block&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;working&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

  &lt;span class="c1"&gt;// Attempt to access "message" outside of the function scope is not possible&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: message is not defined at calcAge&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1975&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have declared &lt;code&gt;working&lt;/code&gt; using &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;message&lt;/code&gt; using &lt;code&gt;const&lt;/code&gt;. When trying to print the variable &lt;code&gt;message&lt;/code&gt;, JavaScript throws an error &lt;code&gt;ReferenceError: message is not defined at calcAge&lt;/code&gt;. This is because the &lt;code&gt;if&lt;/code&gt; block creates a scope for this variable, which is only accessible within that block scope. &lt;/p&gt;

&lt;p&gt;However, there is no error when trying to access &lt;code&gt;working&lt;/code&gt; outside the code block. As explained before, this is because &lt;code&gt;var&lt;/code&gt; is not block scoped, it's function scoped. So you can access &lt;code&gt;working&lt;/code&gt; inside the &lt;code&gt;calcAge()&lt;/code&gt; function since it's the current function scope. But if we try to access the &lt;code&gt;working&lt;/code&gt; outside the &lt;code&gt;calcAge()&lt;/code&gt; function, then JavaScript will throw an error. &lt;/p&gt;

&lt;h3&gt;
  
  
  Scope can be nested
&lt;/h3&gt;

&lt;p&gt;The scope can be nested, which means you can create functions inside another function, block inside another function, function inside another block, or block inside a block. &lt;/p&gt;

&lt;p&gt;The scope contained within another scope is named &lt;em&gt;inner scope&lt;/em&gt;. And the scope that wraps another scope is named &lt;em&gt;outer scope&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;When there are nested scopes, the inner scope can also access the outer scope variables. But outside of the scopes, these variables are not accessible. So outer scope does not have access to the variables of inner functions or blocks.&lt;/p&gt;

&lt;p&gt;Check the below example to understand this behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Outer function&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;birthyear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Peter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;birthyear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Inner block&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is still employed!`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Inner function&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;yearsToRetire&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;retirement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; will be retired in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;retirement&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;yearsToRetire&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1975&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the &lt;code&gt;yearsToRetire()&lt;/code&gt; function and &lt;code&gt;if&lt;/code&gt; block are nested inside the &lt;code&gt;calcAge()&lt;/code&gt; function. To calculate the &lt;code&gt;retirement&lt;/code&gt;, we have accessed the &lt;code&gt;age&lt;/code&gt; variable, which is declared in the outer scope, inside the &lt;code&gt;calcAge()&lt;/code&gt; function. &lt;/p&gt;

&lt;p&gt;Also, we have accessed the &lt;code&gt;userName&lt;/code&gt; variable, which is declared in the &lt;code&gt;calcAge()&lt;/code&gt; function scope, in both &lt;code&gt;yearsToRetire()&lt;/code&gt; function and &lt;code&gt;if&lt;/code&gt; block. We can look outwards to access variables in the parent's scope with nested scope. It could be a variable inside an outer function, outer block, or a global variable.  &lt;/p&gt;

&lt;p&gt;I hope now you have a better understanding of global, function, and block scope. However, before moving to the scope chain, there is one more scope that we should learn, which is lexical scope. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640057494898%2FUOECh3Fni.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640057494898%2FUOECh3Fni.gif" alt="another-scope.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Lexical Scope
&lt;/h2&gt;

&lt;p&gt;Lexical scoping means that organizing and accessing variables are controlled by where we write our functions and code blocks. &lt;/p&gt;

&lt;p&gt;For example, a function that is written inside another function has access to the variables of the parent function despite where the function is invoked. &lt;/p&gt;

&lt;p&gt;So the lexical scoping means that the scope is defined at the location where the variable or function is defined, and not where they run.&lt;/p&gt;

&lt;p&gt;Let's check the below example to understand this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Peter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sayUserName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sayUserNameAgain&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sarah&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// Invoke the first function&lt;/span&gt;
  &lt;span class="nf"&gt;sayUserName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;sayUserNameAgain&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Peter&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what has happened here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the &lt;code&gt;sayUserNameAgain()&lt;/code&gt; function is called, it creates a local variable &lt;code&gt;userName&lt;/code&gt; and sets its value as &lt;code&gt;Sarah&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;In the next line, the &lt;code&gt;sayUserName()&lt;/code&gt; function is called, and &lt;code&gt;sayUserName()&lt;/code&gt; function is defined outside the &lt;code&gt;sayUserNameAgain()&lt;/code&gt; function. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sayUserName()&lt;/code&gt; function logs the &lt;code&gt;userName&lt;/code&gt; variable, but &lt;code&gt;userName&lt;/code&gt; is not defined in the &lt;code&gt;sayUserName()&lt;/code&gt; scope. So we have to go up one scope to the global scope to get the value of &lt;code&gt;userName&lt;/code&gt; which is &lt;code&gt;Peter&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Even though we have &lt;code&gt;userName = "Sarah"&lt;/code&gt; right above where the &lt;code&gt;sayUserName()&lt;/code&gt; function invokes, we have never accessed that value. &lt;/li&gt;
&lt;li&gt;This is because lexical scoping requires us to go where the functions are defined, not where they
run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope now you understand what lexical scope is. So let's move on to the scope chain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scope Chain
&lt;/h2&gt;

&lt;p&gt;The scope chain is how Javascript looks for variables. When looking for variables through the nested scope, the inner scope first looks at its own scope. If the variable is not assigned locally, which is inside the inner function or block scope, then JavaScript will look at the outer scope of said function or block to find the variable. If Javascript could not find the variable in any of the outer scopes on the chain, it will throw a reference error. &lt;/p&gt;

&lt;p&gt;Let's take an example and go through this process step by step. Check the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Global variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Peter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Outer function&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;birthyear&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentYear&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;birthyear&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="c1"&gt;// inner block&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;working&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Peter is still employed!`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// inner function&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;yearsToRetire&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;retirement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; will be retired in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;retirement&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;yearsToRetire&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;calcAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1975&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We have a global variable called &lt;code&gt;userName&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We have an outer function &lt;code&gt;calcAge()&lt;/code&gt;,  which is in the global scope.&lt;/li&gt;
&lt;li&gt;We have an inner function, &lt;code&gt;yearsToRetire()&lt;/code&gt;, nested inside &lt;code&gt;calcAge()&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;Also, we have an &lt;code&gt;if&lt;/code&gt; block inside the &lt;code&gt;calcAge()&lt;/code&gt; function. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the above example, let's try to understand how the scope chain works. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640110364705%2FsYmJD6k6H.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640110364705%2FsYmJD6k6H.png" alt="1-global-scope.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, we have the global scope, which has only one variable, &lt;code&gt;userName&lt;/code&gt;. There is a function declared in the global scope, which is &lt;code&gt;calcAge()&lt;/code&gt;. But to keep things simple, let's focus on the variables. And keep in mind that function and variables work the same way in the scope chain. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640114481151%2Fzbcw0mnab.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640114481151%2Fzbcw0mnab.gif" alt="1-scope-chain.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you remember, each function creates its own scope. So inside the global scope, the first function scope is created with the &lt;code&gt;calcAge()&lt;/code&gt; function. &lt;/p&gt;

&lt;p&gt;Inside the &lt;code&gt;calcAge()&lt;/code&gt; function there are two variables declared, which are &lt;code&gt;currentYear&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt;. Also, we have access to the global variable &lt;code&gt;userName&lt;/code&gt; inside the &lt;code&gt;calcAge()&lt;/code&gt; function. &lt;/p&gt;

&lt;p&gt;If we have any need to access the variable &lt;code&gt;userName&lt;/code&gt; inside this function, then JavaScript looks inside the &lt;code&gt;calcAge()&lt;/code&gt; function to see whether the variable is declared inside the scope. When JavaScript can't find it there, it will reach out to the outer scope, that is the global scope. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640114614074%2F0S-z_7nQ0x.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640114614074%2F0S-z_7nQ0x.gif" alt="2-scope-chain.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, inside the first scope, there is a second function, &lt;code&gt;yearsToRetire()&lt;/code&gt;, which also creates its own scope containing the &lt;code&gt;retirement&lt;/code&gt; variable set to &lt;code&gt;60 - age&lt;/code&gt;. Now we have a nested structure of scopes with one scope inside the other.&lt;/p&gt;

&lt;p&gt;We have a string that needs access to &lt;code&gt;userName&lt;/code&gt; variable inside this function. Since JavaScript cannot find this variable within the local scope, it will look up in the scope chain until it finds the variable and uses it. &lt;/p&gt;

&lt;p&gt;Also, inside this &lt;code&gt;yearsToRetire()&lt;/code&gt; function scope we also have the access to variables inside the &lt;code&gt;caclAge&lt;/code&gt; function scope, since &lt;code&gt;caclAge&lt;/code&gt; is the parent scope and outer scope of &lt;code&gt;yearsToRetire()&lt;/code&gt; function. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640114721366%2FgNG062g6_.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640114721366%2FgNG062g6_.gif" alt="3-scope-chain.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is an &lt;code&gt;if&lt;/code&gt; block inside the &lt;code&gt;calcAge()&lt;/code&gt; function, which has the two variables declared inside that. However, as I explained earlier, the variable declared with &lt;code&gt;var&lt;/code&gt; is not block scoped. So the variable &lt;code&gt;working&lt;/code&gt; will be a part of the &lt;code&gt;calcAge()&lt;/code&gt; function scope. Since the &lt;code&gt;working&lt;/code&gt; is in the &lt;code&gt;calcAge()&lt;/code&gt; function scope, the &lt;code&gt;yearsToRetire()&lt;/code&gt; function scope also has access to it. &lt;/p&gt;

&lt;p&gt;The scope chain applies to block scope as well. Therefore, the &lt;code&gt;if&lt;/code&gt; block scope gets access to all the variables from its outer scope. So the block scope can access the variable inside the &lt;code&gt;calcAge()&lt;/code&gt; function scope and global scope. &lt;/p&gt;

&lt;p&gt;Another important thing to remember is that the &lt;code&gt;if&lt;/code&gt; block scope does not have access to any variables in the &lt;code&gt;yearsToRetire()&lt;/code&gt; function scope, and vice versa. The reason for this is lexical scoping. &lt;/p&gt;

&lt;p&gt;The way we can access variables depends on where the scope is placed or where it is written in the code. In this scenario, none of these two scopes is written inside one another. We could say that they are sibling scopes since they are both child scopes of the &lt;code&gt;calcAge()&lt;/code&gt; function scope. So, according to the lexical scoping, they cannot access each other's variables. Scope chain only works upwards, not sideways.  &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640112694935%2FKz31xXYq_.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640112694935%2FKz31xXYq_.png" alt="2-scope-chain.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So this is how the scope chain works. If one scope needs to use a certain variable but cannot find it in the scope, it will look up in the scope chain and check whether it can find a variable on one of the outer scopes. If the variable is available in the outer scope, then the child scope has the access to it. If it is not there in any outer scopes, the JavaScript will throw a reference error. So this process is called &lt;em&gt;variable lookup&lt;/em&gt;. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640113928736%2FdgeL_A2zY.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1640113928736%2FdgeL_A2zY.gif" alt="we-are-done.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this post helped you understand the different types of scopes in JavaScript and how the scope chain works. &lt;/p&gt;

&lt;p&gt;Happy coding! &lt;/p&gt;




&lt;p&gt;&lt;a href="https://dasha.ai/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F75135110%3Fs%3D50%26v%3D4" alt="Visit Dasha AI"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Join  &lt;a href="https://community.dasha.ai/" rel="noopener noreferrer"&gt;Dasha Developer Community&lt;/a&gt; where you’ll meet welcoming like-minded developers who share ideas, questions, and get all the help they need to build cool conversational AI apps (for free, of course).&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Slice and Splice JavaScript Arrays Like a Pro</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Tue, 07 Dec 2021 09:23:41 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/slice-and-splice-javascript-arrays-like-a-pro-2d9d</link>
      <guid>https://dev.to/sumusiriwardana/slice-and-splice-javascript-arrays-like-a-pro-2d9d</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article was originally published on &lt;a href="https://dasha.ai/en-us/blog/javascript-arrays-slice-and-splice" rel="noopener noreferrer"&gt;Dasha.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In case you are wondering, Dasha is a &lt;strong&gt;conversational-AI-as-a-service&lt;/strong&gt; platform that lets you embed realistic voice and text conversational capabilities into your apps or products.  &lt;a href="https://auth.dasha.ai/account/register" rel="noopener noreferrer"&gt;Start building for free!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Do you find yourself looking up the difference between slice() and splice() methods all the time?&lt;/p&gt;

&lt;p&gt;The two methods are among the most used array methods when it comes to adding, updating, or removing items in an array, and cloning an array or copying a portion of an array.  ​&lt;/p&gt;

&lt;p&gt;Slice() and splice() methods look similar, and they sound similar, so it's very easy to get confused and remember which is which. I've put together this guide on these two methods so that you can slice and splice JavaScrips arrays like a pro. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637390493075%2F6vSKjLJt-.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637390493075%2F6vSKjLJt-.png" alt="slice-vs-splice.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Slice() Method
&lt;/h2&gt;

&lt;p&gt;The slice() method copies a chunk (or slice) from an array and returns that copied part as a new array. It does not modify or change the original array. Instead, it creates a new shallow copy of the original array.&lt;/p&gt;

&lt;p&gt;This method takes two optional arguments. The first argument is the &lt;code&gt;startIndex&lt;/code&gt;, and the second is the &lt;code&gt;endIndex&lt;/code&gt;.  If you do not pass any arguments, the entire original array will be copied by default. Also, If the arguments you pass are greater than the actual array, it will return an empty array. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// No arguments&lt;/span&gt;
&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="err"&gt;​&lt;/span&gt;&lt;span class="c1"&gt;// One argument&lt;/span&gt;
&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="err"&gt;​&lt;/span&gt;&lt;span class="c1"&gt;// Two arguments&lt;/span&gt;
&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;endIndex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;startIndex&lt;/code&gt;: 

&lt;ul&gt;
&lt;li&gt;The index where the slice should begin. &lt;/li&gt;
&lt;li&gt;If the value is omitted, it will start at 0. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;endIndex&lt;/code&gt;: 

&lt;ul&gt;
&lt;li&gt;The slice will end before this index. So, for example, adding &lt;code&gt;index 4&lt;/code&gt; will slice up to &lt;code&gt;index 3&lt;/code&gt;, omitting the value of &lt;code&gt;index 4&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;If the &lt;code&gt;endIndex&lt;/code&gt; value is omitted, it will slice to the end of the array. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let's slice an array with no arguments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteFood&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍕&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍔&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🌮&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍨&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;slicedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;favoriteFood&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slicedArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ["🍕", "🍔", "🌮", "🍨"]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favoriteFood&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;slicedArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, since there are no arguments, it has returned a copy of the entire array. &lt;/p&gt;

&lt;p&gt;One important thing to note here is that these two arrays are not equal! They are two separate arrays containing the same values inside them. So if you check their equality as in the example, it will return &lt;code&gt;false&lt;/code&gt;.   &lt;/p&gt;

&lt;p&gt;Now let's check how we can slice an array with a single argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteFood&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍕&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍔&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🌮&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍨&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;slicedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;favoriteFood&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slicedArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ["🍔", "🌮", "🍨"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you pass a single argument to the slice() method, it grabs all the elements from that argument until the end of the array, including the index in the argument. So in our example, we have made a copy from &lt;code&gt;index 1&lt;/code&gt; to &lt;code&gt;favoriteFood.length - 1&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Here's a visual representation of our example:&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637484088868%2F-AVxMvauj.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637484088868%2F-AVxMvauj.gif" alt="slice-example-1.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's move on to slicing an array by passing two arguments. &lt;/p&gt;

&lt;p&gt;Imagine that we want to copy only the &lt;code&gt;🍔&lt;/code&gt; and &lt;code&gt;🌮&lt;/code&gt; from our previous example to a new array. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637484107516%2Frr4aTSu9U.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637484107516%2Frr4aTSu9U.gif" alt="slice-example-2.gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteFood&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍕&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍔&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🌮&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍨&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;slicedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;favoriteFood&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slicedArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ["🍔", "🌮"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​&lt;br&gt;
In the above example, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We have added &lt;code&gt;index 1&lt;/code&gt; as the first argument. Remember that the first argument includes the index itself when slicing the array.&lt;/li&gt;
&lt;li&gt;As the second argument, we have added &lt;code&gt;index 3&lt;/code&gt;. But it doesn't include the index when slicing the array. Instead, it only includes the elements up to that index. In this case, it will grab only up to &lt;code&gt;index 2&lt;/code&gt;. 
This array slice returns a new array with &lt;code&gt;🍔&lt;/code&gt; and &lt;code&gt;🌮&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another thing that we can do with the slice() method is that use negative numbers for arguments. Let's see how this works with the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteFood&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍕&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍔&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🌮&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍨&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;slicedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;favoriteFood&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slicedArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ["🍔", "🌮", "🍨"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have added a single argument as &lt;code&gt;-3&lt;/code&gt;. This will start counting from the end of the array and slice it (not the beginning from the array). If we have given &lt;code&gt;-2&lt;/code&gt;, it will return only &lt;code&gt;["🌮", "🍨"]&lt;/code&gt;. This is very useful when you want to get the last element of the array, and then you just have to use  &lt;code&gt;-1&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The slice() method is very useful for cloning an array, copying a portion of an array, and converting an array-like object into an array. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637413072435%2FFqfF-SItr.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637413072435%2FFqfF-SItr.gif" alt="slice-it-all.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Splice() Method
&lt;/h2&gt;

&lt;p&gt;The splice() method helps you add, update, and remove elements in an array. This method modifies the array and does not create a new array. It will also return a new array with all the elements you have removed, which is helpful if you want to track what has been removed.  &lt;/p&gt;

&lt;p&gt;The splice() method takes several arguments to decide which elements to delete, the delete count, and what elements to add. You can check further details on these parameters below. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// general&lt;/span&gt;
&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// With the optional parameters&lt;/span&gt;
&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;deleteCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newElement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Parameters&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;start&lt;/code&gt;(required): 

&lt;ul&gt;
&lt;li&gt;The index where the slice should begin for removing elements in the array.&lt;/li&gt;
&lt;li&gt;If the &lt;code&gt;start&lt;/code&gt; is negative, it will count backward from the end of the array.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;deleteCount&lt;/code&gt; (optional): 

&lt;ul&gt;
&lt;li&gt;The number of elements to be deleted from that index.&lt;/li&gt;
&lt;li&gt;If you don't specify the &lt;code&gt;deleteCount&lt;/code&gt;, it will delete everything in the array after the &lt;code&gt;startIndex&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;newElement&lt;/code&gt; (optional):  The new element(s) to be added to the array.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Let's see how to remove elements with a single argument, with only the &lt;code&gt;start&lt;/code&gt; parameter. &lt;/p&gt;

&lt;p&gt;We have our favorite fruits in the array below, and we want to remove the last two fruits. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637484129639%2F1UjQsUjgB.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637484129639%2F1UjQsUjgB.gif" alt="splice-example-1.gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍓&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🥑&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍊&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍇&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;removedFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;favoriteFruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favoriteFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//  ["🍓", "🥑"]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;removedFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//   ["🍊", "🍇"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have added the &lt;code&gt;start&lt;/code&gt; parameter as &lt;code&gt;2&lt;/code&gt;, and that's where it has started removing things from this array. Since we haven't specified a second parameter, it has removed everything after &lt;code&gt;index 2&lt;/code&gt;, including the &lt;code&gt;index 2&lt;/code&gt; element. So now the &lt;code&gt;favoriteFruits&lt;/code&gt; only includes &lt;code&gt;["🍓", "🥑"]&lt;/code&gt;. And you can see the removed item in the array, &lt;code&gt;removedFruits&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you add &lt;code&gt;0&lt;/code&gt; as the &lt;code&gt;start&lt;/code&gt; parameter without any other parameters, it will remove everything from the array and change it to an empty array. Also, if you add any number higher than the largest index number of the array, it will not affect the original array. &lt;/p&gt;

&lt;p&gt;So what happens if we add a negative number as the &lt;code&gt;start&lt;/code&gt; parameter? If the &lt;code&gt;start&lt;/code&gt; is negative, it will count backward from the end of the array and remove the elements. Check the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍓&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🥑&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍊&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍇&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;removedFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;favoriteFruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favoriteFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//  ["🍓"]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;removedFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//   ["🥑", "🍊", "🍇"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have added the &lt;code&gt;start&lt;/code&gt; parameter as &lt;code&gt;-3&lt;/code&gt;. This will start counting from the end of the array and remove items. If we have given &lt;code&gt;-2&lt;/code&gt;, the original array will return &lt;code&gt;["🍊", "🍇"]&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Now let's see how to remove elements with the &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;deleteCount&lt;/code&gt; parameters. &lt;/p&gt;

&lt;p&gt;Check the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍓&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🥑&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍊&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍇&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;removedFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;favoriteFruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favoriteFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//  ["🍓", "🍇"]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;removedFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//   ["🥑", "🍊"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we removed elements starting from &lt;code&gt;index 1&lt;/code&gt; and removed two elements. And it has modified the original array with the remaining elements and returned an array with the removed elements. &lt;/p&gt;

&lt;p&gt;So let's move on to adding elements to the array with the &lt;code&gt;newElement&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;You can add a continuous list of elements separated by commas. Let's add two additional fruits to our favorite Fruits. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637484162373%2FqqhwUIF0D.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637484162373%2FqqhwUIF0D.gif" alt="splice-exaple-3.gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍓&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🥑&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍊&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍇&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;removedFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;favoriteFruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍏&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🍒&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favoriteFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//  ["🍓", "🍏", "🍒", "🍊", "🍇"]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;removedFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//   ["🥑"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what we have done here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We removed &lt;code&gt;"🥑"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We set the &lt;code&gt;deleteCount&lt;/code&gt; as &lt;code&gt;1&lt;/code&gt; since we want to remove only one element.&lt;/li&gt;
&lt;li&gt;And we added &lt;code&gt;"🍏", "🍒"&lt;/code&gt; to the array where we remove the elements. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can add any number of elements to the array by separating them by commas. When we add elements to the array, the array will grow in length. Also, if you don't want to remove any items, you can simply add the second parameter as &lt;code&gt;0&lt;/code&gt;. &lt;br&gt;
​&lt;br&gt;
The splice() method is mainly used when you need to delete or add new elements to an array. And you can either assign the returned array to a variable or ignore it as you wish. &lt;/p&gt;

&lt;p&gt;Now we have a clear idea about how slice() and splice() methods work. You can find out what's the main differences between these two methods below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Slice() vs. Splice()
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Slice()&lt;/th&gt;
&lt;th&gt;Splice()&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Does not modify the original array&lt;/td&gt;
&lt;td&gt;Modifies the original array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;This method is used to get a new array by selecting a sub-array of a given array.&lt;/td&gt;
&lt;td&gt;This method is used to add/remove an item from the given array.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The result has to be assigned to a new array variable.&lt;/td&gt;
&lt;td&gt;The result is not required to assign to a new variable.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Takes two arguments, both being optional.&lt;/td&gt;
&lt;td&gt;Takes 3 arguments, the last two arguments being optional, and the last argument can have any number of parameters (just remember that you don't have to pass it as an array type).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The second argument represents an index.&lt;/td&gt;
&lt;td&gt;The second argument represents the count.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;I hope this post helps you clear the confusion between these two methods. I use one trick to remember things: &lt;strong&gt;the letter "p" of the splice() referred to as &lt;em&gt;permanently modifying&lt;/em&gt; the array&lt;/strong&gt;. I hope it will help you as well 😊&lt;/p&gt;

&lt;p&gt;Happy Coding! &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637433934605%2FoI5ngNT_V.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637433934605%2FoI5ngNT_V.gif" alt="happy-coding.gif"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://dasha.ai/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F75135110%3Fs%3D50%26v%3D4" alt="Visit Dasha AI"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Join  &lt;a href="https://community.dasha.ai/" rel="noopener noreferrer"&gt;Dasha Developer Community&lt;/a&gt; where you’ll meet welcoming like-minded developers who share ideas, questions, and get all the help they need to build cool conversational AI apps (for free, of course).&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>JavaScript Arrays: Explain Like I'm Five</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Mon, 22 Nov 2021 11:38:17 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/javascript-arrays-explain-like-im-five-33ak</link>
      <guid>https://dev.to/sumusiriwardana/javascript-arrays-explain-like-im-five-33ak</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article was originally published on &lt;a href="https://dasha.ai/en-us/blog/javascript-arrays" rel="noopener noreferrer"&gt;Dasha.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In case you are wondering, Dasha is a &lt;strong&gt;conversational-AI-as-a-service&lt;/strong&gt; platform that lets you embed realistic voice and text conversational capabilities into your apps or products.  &lt;a href="https://auth.dasha.ai/account/register" rel="noopener noreferrer"&gt;Start building for free!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;The array is one of the fundamental and crucial concepts you encounter when learning JavaScript. Moreover, it is one data structure that many other complex ones build off. So it's important to have a solid foundational understanding and knowledge of arrays for your programming journey. &lt;/p&gt;

&lt;p&gt;Let me ask you this,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have you used a simple To-do app before?&lt;/li&gt;
&lt;li&gt;Have you used a music app where you store playlists?&lt;/li&gt;
&lt;li&gt;Have you seen any leaderboard applications?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have used any of these applications before, the chance is most of these apps must have used arrays to store these data lists. &lt;/p&gt;

&lt;p&gt;Arrays are powerful data structures, and it's essential to understand how to use them. This post will cover what arrays are, how to create them, and a few array methods you will commonly use.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636902251180%2FxTE5pRgtS.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636902251180%2FxTE5pRgtS.jpeg" alt="arrays-everywhere.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an Array?
&lt;/h2&gt;

&lt;p&gt;Arrays are used to store multiple values in JavaScript. You can think of an array as an ordered list of values. Arrays organize their items in logical order or sequentially. Also, arrays have built-in methods that make it easy to lookup, add, or remove elements based on their position.  &lt;/p&gt;

&lt;p&gt;Let's think that we have The Millenium Falcon ship. We have a few of the Star Wars characters on board. Now we want to store these data in our array. &lt;/p&gt;

&lt;p&gt;So here's a visual representation of our array:&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636978171392%2Ffc5-4EfQqW.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636978171392%2Ffc5-4EfQqW.png" alt="Starwars.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see that Hans, Luke, Leia, and Chewbacca are staying next to each other. This is what we meant by arrays organizing their items in logical order or sequentially. &lt;/p&gt;

&lt;p&gt;This is very helpful when accessing items because the computer already knows where the value is located. It's because there's a number that refers to the location or position where the value is stored. We call this &lt;code&gt;index&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The array index starts with 0, and as you move further to the right, the index increases by one. This numbering method is called &lt;em&gt;Zero-Based Numbering&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So, for example, in the above array, Hans is at &lt;code&gt;index 0&lt;/code&gt;, Luke is at &lt;code&gt;index 1&lt;/code&gt;, Leia is at &lt;code&gt;index 2&lt;/code&gt;, and so on. Check the below picture.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636978534577%2Fa8AEe281P.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636978534577%2Fa8AEe281P.png" alt="Starwars-2.png"&gt;&lt;/a&gt;&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637265175730%2FUW_IqQdq3.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637265175730%2FUW_IqQdq3.jpeg" alt="arrays-starts-at-1.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A fun fact about JavaScript is that arrays are dynamic, which means that the size of the array can grow or shrink as needed. It does not have static arrays where you have to set a fixed length specifically. &lt;/p&gt;

&lt;p&gt;You can store any type of data in an array. For example, you can store boolean, strings, numbers, characters, objects, or even other arrays. And, it's possible to create an array with elements of multiple data types. This means creating an array with a number in the first position, a string in the second, an object in the third, etc.&lt;/p&gt;

&lt;p&gt;Here's an array with different types of elements:&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636976691244%2FGGrCGoU4g.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636976691244%2FGGrCGoU4g.png" alt="Starwars-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before moving into array methods and adding and removing elements with array methods, let's look at the &lt;code&gt;length&lt;/code&gt; property.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;length&lt;/code&gt; property
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;length&lt;/code&gt; property returns the size of the array. When you access the length, it simply returns the value of the biggest &lt;strong&gt;index + 1&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;If you wonder why it is adding &lt;code&gt;1&lt;/code&gt; to the index, if you remember, the index starts with 0, so to get the actual number of elements, it doesn't count the elements; it gets the biggest numeric index plus one. &lt;/p&gt;

&lt;p&gt;You can find out the length of the array with the &lt;code&gt;length&lt;/code&gt; property as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Array Methods
&lt;/h2&gt;

&lt;p&gt;JavaScript’s standard library contains lots of array methods that help manipulate arrays easily. For example, there are methods to add and remove items in an array. And there are methods to find and filter items. In this post, we will go through basic array methods to add and remove items from an array. &lt;/p&gt;

&lt;p&gt;Now let's see how to create an array and work with arrays.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create an array
&lt;/h2&gt;

&lt;p&gt;There are a few ways to create an array in JavaScript. In this post, we will go through how to create an array with &lt;code&gt;array literal&lt;/code&gt; and &lt;code&gt;array constructor&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating an array with the array literal&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The array literal uses the square brackets &lt;code&gt;[]&lt;/code&gt; to wrap a list of elements separated by commas. This is the most common way of creating an array. &lt;/p&gt;

&lt;p&gt;Let's declare an array with our Star Wars characters using the array literal notation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The items or the values are defined between the open and closing brackets, and a comma separates each value. We have to add the values in an array as we add variables, which means if we add strings, we have to use quotation marks. &lt;/p&gt;

&lt;p&gt;You can declare an empty array with empty brackets as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating an array with the array constructor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can create the same array with the array constructor. However, the syntax is slightly different with the &lt;code&gt;new&lt;/code&gt; keyword. Check the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we create arrays with numbers using the array constructor, it behaves a little bit differently,  especially when we add only one number. For example, if we create an array with one numerical value, &lt;code&gt;let myArray = new Array(4)&lt;/code&gt;, it will create a list with no elements but with a length equal to 4. So &lt;code&gt;['Han']&lt;/code&gt; is identical to the &lt;code&gt;new Array('Han')&lt;/code&gt; but &lt;code&gt;[4]&lt;/code&gt; is not the same thing as to the &lt;code&gt;new Array(4)&lt;/code&gt;. Check the below example to understand this behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Array with one string&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;    &lt;span class="c1"&gt;// "Hans"&lt;/span&gt;

&lt;span class="c1"&gt;// Array with one numerical value&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 4&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;  &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;  &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;  &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;  &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the array &lt;code&gt;myArray&lt;/code&gt; length is set to 4 since we have added one numerical value that sets the length. And it has created a list with no elements, so the value of each position is &lt;code&gt;undefined&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To create an empty array, you can simply declare an empty array with no parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to access elements of an array
&lt;/h2&gt;

&lt;p&gt;I hope you remember that array elements already have assigned indexes positions. We can refer to this index number to access each element using the square brackets &lt;code&gt;[]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's see how we can access each member from our Millennium Falcon Ship.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;  &lt;span class="c1"&gt;// "Hans"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;  &lt;span class="c1"&gt;// "Luke"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;  &lt;span class="c1"&gt;// "Leia"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;  &lt;span class="c1"&gt;// "Chewbacca"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arrays can contain other arrays since it is capable of having multi-dimensional arrays. So how can we access these arrays inside arrays? Let's take an example of a multi-dimensional array representing a Star Wars family. &lt;/p&gt;

&lt;p&gt;Here's a visual representation of our multi-dimensional array:&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637120579431%2Fl2dRtqwM4.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637120579431%2Fl2dRtqwM4.png" alt="Starwars-3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we can write this array as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Anakin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Padme&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if we want to access "Leia", we can see that she is at &lt;code&gt;index 1&lt;/code&gt; inside the nested array, which is positioned at &lt;code&gt;index 2&lt;/code&gt; of the main array. Are you confused? Check the below picture. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637120988072%2FjrM79ms58G.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637120988072%2FjrM79ms58G.png" alt="Starwars-4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, to access Leia, we have to refer to these two index numbers as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;leia&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;leia&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//  "Leia"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add elements to an array
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Adding elements with index&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You have seen that we can access every element in an array by calling its index. We can add items to an array by simply setting the value to the index number as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Anakin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 'Hans', 'Luke', 'Leia', 'Chewbacca', 'Anakin'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I added an element at &lt;code&gt;index 4&lt;/code&gt; of the array, which didn’t exist before but now has the value “Anakin”. &lt;/p&gt;

&lt;p&gt;What happens if we add an element to an already existing value? For example, if we add an element to &lt;code&gt;index 3,&lt;/code&gt; what would happen? &lt;/p&gt;

&lt;p&gt;When you add an element to an already existing value, it will replace the original value. So it will modify or change the element. Check the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Padme&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 'Hans', 'Padme', 'Leia', 'Chewbacca'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, you have to be mindful when you declare elements with an index. If you add an element with a given index and there are no other elements in-between, the array will create a list of all the elements without a value. Check the below example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 7&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//'Hans', 'Luke', undefined, undefined, undefined, undefined, 'Leia'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what we have done here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We have created an array with two elements.&lt;/li&gt;
&lt;li&gt;We have added another element at &lt;code&gt;index 6&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;This has modified the array length to 7.&lt;/li&gt;
&lt;li&gt;The values for indexes 2, 3, 4, 5 are undefined since we haven't added any elements to these indexes. &lt;/li&gt;
&lt;/ul&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637265421355%2FwLCSsBGmV.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637265421355%2FwLCSsBGmV.gif" alt="bad-feeling.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding elements to the end of an array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;push()&lt;/code&gt; method allows us to add one or several items at the end of an array. &lt;/p&gt;

&lt;p&gt;Let's add a few more members to our Star Wars crew 😊&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Adds "Anakin" and "Padme" at the end of the array&lt;/span&gt;
&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Anakin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Padme&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//'Hans', 'Luke', 'Leia', 'Chewbacca', 'Anakin', 'Padme'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we consider the performance, the &lt;code&gt;push()&lt;/code&gt; method runs fast because it does not need to move any indexes since it adds elements to the end, and other elements keep their indexes.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637261140884%2Fc2FsBXDOB.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637261140884%2Fc2FsBXDOB.png" alt="Starwars-push.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding elements to the beginning of an array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;unshift()&lt;/code&gt; method allows us to add one or several items to the beginning of an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Adds "R2-D2" and "BB-8" at the beginning of the array&lt;/span&gt;
&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unshift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;R2-D2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BB-8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//'R2-D2', 'BB-8', 'Hans', 'Luke', 'Leia', 'Chewbacca'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;unshift ()&lt;/code&gt; method is slow in performance. When an element is added to the beginning of an array, all the other elements have to shift right, renumber them from the index 0 to 1, from 1 to 2, etc. So when there are more elements in the array, more time is taken to move them, consuming more in-memory operations. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637262910362%2FaQdRmr96s.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637262910362%2FaQdRmr96s.png" alt="Starwars-unshift.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove elements from an array
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Remove elements from the end of an array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;pop()&lt;/code&gt; method removes the last item from an array. We don't have to pass a parameter here since it would be the last item removed when calling this method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Removes "Chewbacca"&lt;/span&gt;
&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 'Hans', 'Luke', 'Leia'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same as the &lt;code&gt;push()&lt;/code&gt; method, this method is also fast when considering the performance. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remove elements from the beginning of an array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;shift()&lt;/code&gt; method removes an element from the beginning of an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hans&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Leia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chewbacca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Removes "Hans"&lt;/span&gt;
&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;milleniumFalconShip&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 'Luke', 'Leia', 'Chewbacca'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;shift()&lt;/code&gt; method is also slow since removing an element first needs to remove the element with the &lt;code&gt;index 0&lt;/code&gt;. Then move all elements to the left, renumber them from the index 1 to 0, from 2 to 1, and so on. So when there are more elements in the array, more time is taken to move them, consuming more in-memory operations.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637262897635%2Fu7-MtpVSN.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637262897635%2Fu7-MtpVSN.png" alt="Starwars-shift.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are the most basic array methods, and there are many more  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#" rel="noopener noreferrer"&gt;other methods&lt;/a&gt;  out there. We will discuss a few more methods in our future articles as well. &lt;/p&gt;

&lt;p&gt;Congratulations! Now you know the basics of JavaScript arrays! &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637256484174%2FkPvw-_ils.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637256484174%2FkPvw-_ils.gif" alt="congratulations.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you find this article simple and that it helps you understand JavaScript arrays more clearly. See you soon with another insightful article on array methods! 😊&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637308113753%2FiUNUYSADC.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637308113753%2FiUNUYSADC.gif" alt="hip-hip-array-1.gif"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://dasha.ai/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F75135110%3Fs%3D50%26v%3D4" alt="Visit Dasha AI"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Join  &lt;a href="https://community.dasha.ai/" rel="noopener noreferrer"&gt;Dasha Developer Community&lt;/a&gt; where you’ll meet welcoming like-minded developers who share ideas, questions, and get all the help they need to build cool conversational AI apps (for free, of course).&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>If-Else or Switch-Case: Which One to Pick?</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Wed, 10 Nov 2021 03:59:21 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/if-else-or-switch-case-which-one-to-pick-4p3h</link>
      <guid>https://dev.to/sumusiriwardana/if-else-or-switch-case-which-one-to-pick-4p3h</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article was originally published on &lt;a href="https://dasha.ai/en-us/blog/javascript-if-else-or-switch-case" rel="noopener noreferrer"&gt;Dasha&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In case you are wondering, Dasha is a &lt;strong&gt;conversational-AI-as-a-service&lt;/strong&gt; platform that lets you embed realistic voice and text conversational capabilities into your apps or products.  &lt;a href="https://auth.dasha.ai/account/register" rel="noopener noreferrer"&gt;Start building for free!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;If you are a newbie to programming and JavaScript, you might be confused about which conditional statements to use, especially between if-else and switch-case statements. &lt;/p&gt;

&lt;p&gt;When I first learned about conditional statements, I thought it was simple enough, and I could use either if-else or switch in any case. But then, when I learned more about this topic and tried to apply it to some problems, I got confused about which one I should use, what's the exact difference, and how I should choose the correct one. &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636281793918%2FGvLEIdJIV.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636281793918%2FGvLEIdJIV.jpeg" alt="FDCKZ2RWYAIMx_2.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I struggled over understanding the difference and application of these two conditional statements and dug deeper into the topic. &lt;/p&gt;

&lt;p&gt;In this article, I will explain these two concepts and provide a comparison chart, so you will understand how you can use if-else and switch-case in different scenarios according to the complexity. &lt;/p&gt;

&lt;p&gt;Before jumping into details, let's refresh our memory on why we use conditional statements in our programs. &lt;/p&gt;

&lt;p&gt;As human beings, we make various decisions all the time that affect our lives. For example, if we have some free time, we have to decide what to do, whether to rest, watch something, call someone or maybe do something productive. &lt;/p&gt;

&lt;p&gt;Conditional statements allow us to make such decisions based on a condition in JavaScript. If the condition is true, we can perform one action, otherwise, we can perform a different action. &lt;/p&gt;

&lt;p&gt;So if-else and switch-case both allow us to make these decisions based on a condition. If you want to refresh your memory on how the conditional works, check out this &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals" rel="noopener noreferrer"&gt;MDN article&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  The if-else and else-if statements
&lt;/h2&gt;

&lt;p&gt;As newbies, we all love if-else statements! 😂&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636282542849%2F7euXxLSu8.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636282542849%2F7euXxLSu8.gif" alt="if-else-matrix.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If-else statement takes a specific condition and checks whether the condition is truthy or falsy. If the condition is true, then the &lt;code&gt;if&lt;/code&gt; statement executes a specific code block. If the condition is false, then the &lt;code&gt;else&lt;/code&gt; statement executes a different code block. &lt;/p&gt;

&lt;p&gt;Let's take a simple example to understand how this works. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario One&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine that you are the class teacher for grade 5, class C. You have to check students' grades based on their marks, and you only have to check whether the student has passed or failed. Let's check one of the student's grades based on their marks using an if-else statement.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;studentGrade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;marks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;marks&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You have passed the exam! 🥳&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You have failed the exam!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;studentGrade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// "You have passed the exam! 🥳"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;According to the above example, we have written a simple function that takes student marks and checks whether it's above 50 or below  50. If the marks entered are 50 or above, then the &lt;code&gt;if&lt;/code&gt; block executes. If it's below 50, then the &lt;code&gt;else&lt;/code&gt; block executes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario Two&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, imagine taking a step further and giving the result based on the students' specific grades. For example, if the student gets an "A+", the student receives "Nailed It! 🥳". If the student gets a "D", the result would be "Failed 😢".   &lt;/p&gt;

&lt;p&gt;To have multiple choices like this, we can use the else-if statements to chain the extra choices. &lt;/p&gt;

&lt;p&gt;See below code written according to the second scenario with else-if statements. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;studentFinalResultIf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nailed It! 🥳&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Passed 💃&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Passed 💃&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Passed 💃&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Barely Survived 😌&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;D&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Failed 😢&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Failed 😢&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;cconsole&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;studentFinalResultIf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;   &lt;span class="c1"&gt;// "Nailed It! 🥳"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;According to the above function, we use different conditional statements to provide students' results depending on the grade. Except for the first code block, which is the &lt;code&gt;if&lt;/code&gt; block, all the other conditions are tested in &lt;code&gt;else if&lt;/code&gt; blocks. And if none of the conditions are true, the last &lt;code&gt;else&lt;/code&gt; executes its code block. &lt;/p&gt;

&lt;h2&gt;
  
  
  Switch statements
&lt;/h2&gt;

&lt;p&gt;The switch statement is a multiple-choice selection statement. Once you have given the choices and relevant expressions for each choice, It looks through the choices until it finds the choice that matches the expression and executes it. &lt;/p&gt;

&lt;p&gt;Let's rewrite the second scenario using the switch statement.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;studentFinalResultSwitch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;grade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nailed It! 🥳&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Passed 💃&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Barely Survived 😌&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;D&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Failed 😢&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Failed 😢&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;studentFinalResultSwitch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;   &lt;span class="c1"&gt;// "Nailed It! 🥳"&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;In the above example, we have the main condition that has many choices. When we check the specific grade, it checks which expression the grade belongs to and then runs that case block. In this case, when the grade is an "A+", it runs &lt;code&gt;case "A+":&lt;/code&gt; and returns the result "Nailed It! 🥳". &lt;/p&gt;

&lt;p&gt;Now you might be thinking both if-else and switch statements are pretty much alike, and maybe if-else seem more straightforward to use. And you might have your reasons for choosing one over the other. So before jumping to any conclusions, let's check the differences between if-else and switch statements. &lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison Chart
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Basic Terms&lt;/th&gt;
&lt;th&gt;If-else&lt;/th&gt;
&lt;th&gt;Switch-case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Check the testing expression&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;An if-else statement can test expression based on a range of values or conditions.&lt;/td&gt;
&lt;td&gt;A switch statement tests expressions based only on a single integer, enumerated value, or string object.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Ideal for&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;if-else conditional branches are great for variable conditions that result into Boolean.&lt;/td&gt;
&lt;td&gt;Switch statements are ideal for fixed data values.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Creation of jump table&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;In the if-else case, we do not create a jump table, and all cases are executed at runtime.&lt;/td&gt;
&lt;td&gt;In switch case, we create jump table on compiled time only selected case is executed on runtime.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Type of search&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;If else implements linear search.&lt;/td&gt;
&lt;td&gt;Switch implements binary switch.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Condition &amp;amp; expression&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Having different conditions is possible.&lt;/td&gt;
&lt;td&gt;We can only have one expression.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Evaluation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;If-else statement evaluates integer, character, pointer or floating-point type or Boolean type.&lt;/td&gt;
&lt;td&gt;Switch statement evaluates only character or integer value.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sequence of execution&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;It is either if-statement will be executed, or else-statement is executed.&lt;/td&gt;
&lt;td&gt;Switch case statement executes one case after another till a break statement appears or until the end of the switch statement is reached.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Default execution&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;If the condition inside if statements are false, then by default, the else statement is executed if created.&lt;/td&gt;
&lt;td&gt;If the condition inside switch statements does not match with any of the cases, for that instance, the default statement is executed if created.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Values&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Values are based on the constraint.&lt;/td&gt;
&lt;td&gt;Values are based on user choice.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Use&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;It is used to evaluate a condition to be true or false.&lt;/td&gt;
&lt;td&gt;It is used to test multiple values of the same variable or expression like 1, 2, 3, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Editing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;It is difficult to edit the if-else statement if the nested if-else statement is used&lt;/td&gt;
&lt;td&gt;It is easy to edit switch cases as they are recognized easily.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;According to the above comparison, you can see the decision of which conditional statement to choose is depending on the scenario and its complexity. For example, we can select both if-else and switch statements for the second scenario since we are just checking one report, which might not make any difference in performance except readability.&lt;/p&gt;

&lt;p&gt;Let's take a step further and make our scenario a little bit complicated. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario Three&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What if we want to print grades for all the students in all classes? Imagine that we have ten classes for grade 5. And each class includes 50 students. So altogether, we have to check and print the results for around 500 students. &lt;/p&gt;

&lt;p&gt;If we use the if-else statement for this, we might run into a slight performance delay. It's because, during the execution, the if-else statement always executes the expression to check whether the condition is satisfied or not. Things would get slower when there are more conditions to check and when the choices get complex. &lt;/p&gt;

&lt;p&gt;On the other hand, a switch statement works comparatively faster because the compiler generates a jump table for switch-cases during compile time. So when the code runs, instead of checking which cases are satisfied, it only decides which cases should be executed. In our third scenario, to generate reports for many students, the switch-case might be the better approach. &lt;/p&gt;

&lt;p&gt;I hope now you can understand that based on the above comparison and our examples, both statements have their place in the code and it's up to you to choose which one suits which scenario. There is no right or wrong way of doing it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So how can we choose which statement to use?&lt;/strong&gt;&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636287323886%2Fsmiwyj8nh.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636287323886%2Fsmiwyj8nh.png" alt="if-switch.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choosing one over the other is not that straightforward. Here are some tips when choosing one over the other;&lt;/p&gt;

&lt;p&gt;You can use if-else when:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The condition result is a &lt;code&gt;boolean&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The conditions are complex. For example,  you have conditions with multiple &lt;a href="https://dasha.ai/en-us/blog/beginners-guide-js-operators-part-2" rel="noopener noreferrer"&gt;logical operators.&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use a switch-case when: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are multiple choices for an expression.&lt;/li&gt;
&lt;li&gt;The condition is based on a predefined set of values such as enums, constants, known types. For example, error codes, statuses, states, object types, etc. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So based on performance, readability, understandability, changeability, you would have to decide whether to use if-else statements or switch statements. When you read more code and write more code, eventually, you will start figuring out which one is suitable for which scenario; it comes with practice. &lt;/p&gt;

&lt;p&gt;Also, there are more approaches if you want to avoid the conditionals as much as you can, especially in JavaScript; array lookup or object lookup are a couple of common approaches. &lt;/p&gt;

&lt;h3&gt;
  
  
  Closing thoughts
&lt;/h3&gt;

&lt;p&gt;You might find it confusing to decide when to use which statement as a newbie, but it gets better with more practice. Remember that every case requires a specific solution but there's no right or wrong answer. And it's up to you to choose a suitable solution based on your experience. So I hope that the comparison provided here makes it easier for you to identify the difference between if-else and switch statements and not pick one side. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If the only tool you have is a hammer, you tend to see every problem as a nail - Abraham Maslow&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Happy coding! &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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636288469628%2FKUlvVssUn.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1636288469628%2FKUlvVssUn.gif" alt="giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.oreilly.com/library/view/high-performance-javascript/9781449382308/ch04.html" rel="noopener noreferrer"&gt;Algorithms and Flow Control&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Statements/switch" rel="noopener noreferrer"&gt;Switch Statement&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else" rel="noopener noreferrer"&gt;If-else Statement&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals" rel="noopener noreferrer"&gt;Making decisions in your code — conditionals&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vivadifferences.com/if-else-vs-switch-case/" rel="noopener noreferrer"&gt;Difference Between If-else and Switch Case&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://dasha.ai/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F75135110%3Fs%3D50%26v%3D4" alt="Visit Dasha AI"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Join  &lt;a href="https://community.dasha.ai/" rel="noopener noreferrer"&gt;Dasha Developer Community&lt;/a&gt; where you’ll meet welcoming like-minded developers who share ideas, questions, and get all the help they need to build cool conversational AI apps (for free, of course).&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Beginner's Guide to JavaScript Operators - Part Two</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Wed, 27 Oct 2021 09:52:24 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/beginners-guide-to-javascript-operators-part-two-6m9</link>
      <guid>https://dev.to/sumusiriwardana/beginners-guide-to-javascript-operators-part-two-6m9</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article was originally published on &lt;a href="https://dasha.ai/en-us/blog/beginners-guide-js-operators-part-2" rel="noopener noreferrer"&gt;Dasha.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In case you are wondering, Dasha is a &lt;strong&gt;conversational-AI-as-a-service&lt;/strong&gt; platform that lets you embed realistic voice and text conversational capabilities into your apps or products.  &lt;a href="https://auth.dasha.ai/account/register" rel="noopener noreferrer"&gt;Start building for free!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Welcome to the second part of the Beginner's Guide to JavaScript Operator! 😊&lt;/p&gt;

&lt;p&gt;To refresh your memory, In the  &lt;a href="https://dev.to/sumusiriwardana/beginners-guide-to-javascript-operators-part-one-eld"&gt;first article&lt;/a&gt;, we have gone through the arithmetic and assignment operators, and operator precedence. &lt;/p&gt;

&lt;p&gt;So let's see what we will be going over in this article. &lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Comparison Operators&lt;/li&gt;
&lt;li&gt;Logical Operators&lt;/li&gt;
&lt;li&gt;Ternary Operators&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;typeof&lt;/code&gt; Operator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kJ9C2OBr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1634698304176/CHu6ZeOmp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kJ9C2OBr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1634698304176/CHu6ZeOmp.gif" alt="lets-get-going.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison Operators
&lt;/h2&gt;

&lt;p&gt;We use comparison operators to compare two values or variables. It is a binary operator which compares the operands and returns whether it's &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; depending on the comparison. &lt;/p&gt;

&lt;p&gt;For example, if you want to check whether &lt;code&gt;10&lt;/code&gt; is greater than &lt;code&gt;8&lt;/code&gt;, we use the greater than operator &lt;code&gt;(&amp;gt;)&lt;/code&gt; and write it as, &lt;code&gt;10 &amp;gt; 8&lt;/code&gt;, then it returns &lt;code&gt;true&lt;/code&gt; because &lt;code&gt;10&lt;/code&gt; is greater than &lt;code&gt;8&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;So, here's a list of comparison operators in JavaScript:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator Name&lt;/th&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;let x = 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;==&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if the operands are equal&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;x == '5'&lt;/code&gt;&lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Not equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if the operands are not equal&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;x != '6'&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strict equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;===&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if the operands are equal and of the same type&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;x === 5&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strict not equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;!==&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if the operands are the same type but are not equal or are different types&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;x !== '5'&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Greater than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if the left operand is greater than the right operand&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;x &amp;gt; 4&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Greater than or equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Retruns &lt;code&gt;true&lt;/code&gt; if left operand is greater than or equal to the right operand&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;x &amp;gt; 5&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Less than&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if the left operand is less than the right operand&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;x &amp;lt; 8&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Less than or equal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if the left operand is less than or equal to the right operand&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;x &amp;lt;= 8&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For equal comparison, we use the &lt;strong&gt;equal operator&lt;/strong&gt; &lt;code&gt;(==)&lt;/code&gt; and the &lt;strong&gt;strict equal operator&lt;/strong&gt; &lt;code&gt;(===)&lt;/code&gt;. Why do we need two different operators for equal comparison? Let's find out. &lt;/p&gt;

&lt;p&gt;There are different data types in JavaScript. When comparing two values of different types, JavaScript tries to convert these different data types into one data type. We call this &lt;strong&gt;type coercion&lt;/strong&gt;. For example, let's say you have to compare a string with a number; JavaScript will try to convert the string into a number or the number into a string so that the values can be compared. &lt;/p&gt;

&lt;p&gt;You can try the below code and see for yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Addition&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;11&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// '111'&lt;/span&gt;

&lt;span class="c1"&gt;//Subtraction&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;11&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, when &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are added together, JavaScript thinks it is string concatenation and converts the value of the &lt;code&gt;b&lt;/code&gt; into a string, and concatenate &lt;code&gt;a&lt;/code&gt;. So the output becomes a string, &lt;code&gt;'111'&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But, when subtracting, JavaScript thinks it's an arithmetic operation so it converts everything into numbers and outputs the value as number &lt;code&gt;10&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Yeah, it's pretty strange! 😂&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XMyBGCja--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1634698355344/QYOCs26Di.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XMyBGCja--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1634698355344/QYOCs26Di.jpeg" alt="type-con.jpg" width="800" height="645"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This topic requires a dedicated post itself. But let's try to get a basic idea of type coercion to understand the difference between equal and strict equal comparison. &lt;/p&gt;

&lt;p&gt;Here is how the &lt;strong&gt;equal operator&lt;/strong&gt; &lt;code&gt;(==)&lt;/code&gt; compares operands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, it converts the value of the operands to a common type, &lt;/li&gt;
&lt;li&gt;Then checks for the equality between them, &lt;/li&gt;
&lt;li&gt;Then compares them and returns the boolean value. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While it looks like the equal operator doesn't consider the data type when comparing the two values. JavaScript actually first converts the values to the same data type implicitly and then compares the operands. Check the below example to understand this behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;//true&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;strict equal operator&lt;/strong&gt; &lt;code&gt;(===)&lt;/code&gt; compares both values and value types. It returns &lt;code&gt;true&lt;/code&gt; only if both values and data types match with the other operand. Check the below example to understand this behavior.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;10&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;//true&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Now you understand how equal comparison works. This same logic applies to &lt;strong&gt;not equal&lt;/strong&gt; and &lt;strong&gt;strict not equal&lt;/strong&gt; comparisons. &lt;/p&gt;

&lt;p&gt;Let's move on to logical operators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Logical Operators
&lt;/h2&gt;

&lt;p&gt;We use logical operators to decide the logic between two variables or values. So it evaluates them and checks whether multiple conditions are &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;, then returns a boolean value.&lt;/p&gt;

&lt;p&gt;First, let's see what are the logical operators and then understand how this basic boolean logic works. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator Name&lt;/th&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Logical AND&lt;/td&gt;
&lt;td&gt;&amp;amp;&amp;amp;&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if both the operands are &lt;code&gt;true&lt;/code&gt;, else returns &lt;code&gt;false&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;true &amp;amp;&amp;amp; true&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;), &lt;br&gt;&lt;code&gt;true &amp;amp;&amp;amp; false&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;false&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logical OR&lt;/td&gt;
&lt;td&gt;| |&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if either of the operands is &lt;code&gt;true&lt;/code&gt;; returns &lt;code&gt;false&lt;/code&gt; if both are &lt;code&gt;false&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;true&lt;/code&gt; | | &lt;code&gt;false&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;), &lt;br&gt;&lt;code&gt;false&lt;/code&gt; | | &lt;code&gt;false&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;false&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logical NOT&lt;/td&gt;
&lt;td&gt;!&lt;/td&gt;
&lt;td&gt;Returns &lt;code&gt;true&lt;/code&gt; if the operand is &lt;code&gt;false&lt;/code&gt; and vice-versa.&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;!true&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;false&lt;/code&gt;) &lt;code&gt;!false&lt;/code&gt; &lt;br&gt;(returns &lt;code&gt;true&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here's see how this boolean logic actually works.&lt;/p&gt;

&lt;p&gt;Check the below picture: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X2KbPL22--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1634698402709/M-rCqGBzA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X2KbPL22--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1634698402709/M-rCqGBzA.png" alt="boolean-logic.png" width="800" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above picture, we have two boolean variables that can be either true or false.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A: Sarah loves coffee &lt;/li&gt;
&lt;li&gt;B: Coffee cup is empty&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now using the boolean operator, we can combine these two variables and use them to make a decision. For example, if Sarah loves coffee and the coffee cup is empty, then we can fill Sarah's coffee cup ☕️&lt;/p&gt;

&lt;p&gt;We can use the truth table in the above picture to quickly calculate the result of the AND and OR operators. &lt;/p&gt;

&lt;p&gt;So if we are using the AND &lt;code&gt;(&amp;amp;&amp;amp;)&lt;/code&gt; logical operator, if all the operands are true, the result would be true. Else, even if one operand is false, then the result would be false. Check the below example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sarahLovesCoffee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// A&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coffeeCupIsEmpty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;  &lt;span class="c1"&gt;// B&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sarahLovesCoffee&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;coffeeCupIsEmpty&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When using the OR &lt;code&gt;(||)&lt;/code&gt; logical operator, the result would be true even if one operand is true, even though the other operands are false. But, if all the operands are false, then the result would be false.  Check the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//At least one operand is true&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sarahLovesCoffee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// A&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coffeeCupIsEmpty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;  &lt;span class="c1"&gt;// B&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sarahLovesCoffee&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;coffeeCupIsEmpty&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="c1"&gt;//Both operands are false&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sarahLovesCoffee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// A&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coffeeCupIsEmpty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;  &lt;span class="c1"&gt;// B&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sarahLovesCoffee&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;coffeeCupIsEmpty&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When it comes to the logical NOT &lt;code&gt;(!)&lt;/code&gt; operator, it inverts the boolean result of the operand (or condition). Check the below example to understand this better.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sarahLovesCoffee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// A&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coffeeCupIsEmpty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;  &lt;span class="c1"&gt;// B&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;sarahLovesCoffee&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;coffeeCupIsEmpty&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's Drake's version of the logic gates 😂&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ldPkfnHd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1634698428500/tjbirw3q1y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ldPkfnHd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1634698428500/tjbirw3q1y.png" alt="drake-boolean.png" width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope that now you understand the basics of logical operators. So let's move on to ternary operators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ternary Operators
&lt;/h2&gt;

&lt;p&gt;The ternary operator or the conditional operator allows us to write something similar to an if-else statement, but all in one line. It uses three operands and evaluates if a condition is true or false, and then returns one of the two values. &lt;/p&gt;

&lt;p&gt;Below is the syntax for the ternary operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;expressionIfTrue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;expressionIfFalse&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, according to the above syntax, If the condition is true, the first expression will be executed. Otherwise, the second expression will be executed. &lt;/p&gt;

&lt;p&gt;Let's say that you want to check the age before deciding whether you are eligible to drive or not. You can simply write it as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;can drive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;can't drive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So if the age 18 or above, then the first expression &lt;code&gt;"can drive"&lt;/code&gt; is executed. Else the second expression &lt;code&gt;"can't drive"&lt;/code&gt; is executed. &lt;/p&gt;

&lt;p&gt;Now, remember that an operator always produces a value.  In other words, an operator is an expression. So if we have a value, we can assign that value to a variable. Because of that, we can make a ternary operator useful to assign a value to a variable conditionally. So we can store the above expression in a variable.&lt;/p&gt;

&lt;p&gt;Check the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;eligibleToDrive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;can drive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;can't drive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;eligibleToDrive&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// "can drive"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what we have done here;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We have declared a variable called &lt;code&gt;age&lt;/code&gt; and given the value of &lt;code&gt;24&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Then, we have declared a variable to check the eligibility to drive - &lt;code&gt;eligibleToDrive&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Then, we have assigned the ternary operator as the value for the &lt;code&gt;eligibleToDrive&lt;/code&gt; variable. In this ternary operator we have given the condition as &lt;code&gt;age &amp;gt;= 18&lt;/code&gt;, the first value as &lt;code&gt;"can drive"&lt;/code&gt; (which will be executed if the condition is true), and the second value as &lt;code&gt;"can't drive"&lt;/code&gt; (which will be executed if the condition is false).&lt;/li&gt;
&lt;li&gt;When we console log the variable, &lt;code&gt;eligibleToDrive&lt;/code&gt;,  it prints the first expression from the ternary operator because the age is greater than 18. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since the ternary operator is just a single line of code, it's often used as a shortened version of a simple if-else statement. &lt;/p&gt;

&lt;p&gt;So that's about the ternary operator! &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;typeof&lt;/code&gt; Operator
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;typeof&lt;/code&gt; operator can tell us about which data type a variable contains. Whether the value is a string, number, boolean, etc. It returns a string indicating the data type. &lt;/p&gt;

&lt;p&gt;Now let's print a few values to see their types.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;             &lt;span class="c1"&gt;// 'boolean'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;            &lt;span class="c1"&gt;// 'boolean'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Peter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;          &lt;span class="c1"&gt;// 'string'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;              &lt;span class="c1"&gt;// 'number'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;              &lt;span class="c1"&gt;// 'number'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="kc"&gt;Infinity&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;         &lt;span class="c1"&gt;// 'number'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;   &lt;span class="c1"&gt;// 'object'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in the above example, with the &lt;code&gt;typeof&lt;/code&gt; operator, we can check the data type of each value. &lt;/p&gt;




&lt;p&gt;Okay, we made it to the end! 😂&lt;/p&gt;

&lt;p&gt;This is all about the basics of JavaScript operators. Of course, there are more to these operators and more operators out there, but you can easily get through them when you understand these basics.&lt;/p&gt;

&lt;p&gt;Thank you for reading this very long beginner's guide to the end!&lt;/p&gt;

&lt;p&gt;Happy coding! 🤗&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eyZ1D6bo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1635076629633/UvGIJxuVE.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eyZ1D6bo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1635076629633/UvGIJxuVE.gif" alt="thank-you.gif" width="480" height="196"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://dasha.ai/" rel="noopener noreferrer"&gt;&lt;img alt="Visit Dasha AI" src="https://res.cloudinary.com/practicaldev/image/fetch/s--R9S_nekr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://avatars.githubusercontent.com/u/75135110%3Fs%3D50%26v%3D4" width="50" height="50"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Join  &lt;a href="https://community.dasha.ai/" rel="noopener noreferrer"&gt;Dasha Developer Community&lt;/a&gt; where you’ll meet welcoming like-minded developers who share ideas, questions, and get all the help they need to build cool conversational AI apps (for free, of course).&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Beginner's Guide to JavaScript Operators - Part One</title>
      <dc:creator>Sumudu Siriwardana</dc:creator>
      <pubDate>Tue, 26 Oct 2021 15:29:58 +0000</pubDate>
      <link>https://dev.to/sumusiriwardana/beginners-guide-to-javascript-operators-part-one-eld</link>
      <guid>https://dev.to/sumusiriwardana/beginners-guide-to-javascript-operators-part-one-eld</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article was originally published on &lt;a href="https://dasha.ai/en-us/blog/beginners-guide-js-operators-part-1" rel="noopener noreferrer"&gt;Dasha.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In case you are wondering, Dasha is a &lt;strong&gt;conversational-AI-as-a-service&lt;/strong&gt; platform that lets you embed realistic voice and text conversational capabilities into your apps or products.  &lt;a href="https://auth.dasha.ai/account/register" rel="noopener noreferrer"&gt;Start building for free!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Have you thought about how we can tell our program to do a specific task? For example, how do we add two numbers together or compare two values?  &lt;/p&gt;

&lt;p&gt;If you remember your arithmetic lessons, we use the &lt;code&gt;+&lt;/code&gt; sign to add two numbers. We use this same sign in JavaScript for additions, and we call them operators.&lt;/p&gt;

&lt;p&gt;In this first article of the beginner's guide to JavaScript operators series, we will explore some of the basic operators in JavaScript! 😊&lt;/p&gt;

&lt;p&gt;Are you ready? 😉&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634695857356%2FC7Z8grolw.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634695857356%2FC7Z8grolw.gif" alt="are-you-ready.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out the Table of Contents below to see what we will be going over in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What are operators and operands?&lt;/li&gt;
&lt;li&gt;Arithmetic Operators&lt;/li&gt;
&lt;li&gt;Assignment Operators&lt;/li&gt;
&lt;li&gt;Operator Precedence&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are operators and operands?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;An operator performs some operation on single or multiple operands (data values) and produces a result.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What does this mean? &lt;/p&gt;

&lt;p&gt;Let's look at the below example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;2 + 3 = 5&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, we have to add &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt; to get the final value. So we are using &lt;code&gt;+&lt;/code&gt; to add these two values. And the final value is &lt;code&gt;5&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;In the above example, the &lt;code&gt;+&lt;/code&gt; sign performs an arithmetic operation to add these two values. So this &lt;code&gt;+&lt;/code&gt; sign is the &lt;strong&gt;operator&lt;/strong&gt; here. In modern programming languages, we use this &lt;code&gt;+&lt;/code&gt; sign to add two values. &lt;/p&gt;

&lt;p&gt;An operand is a data value that the operator will carry out the actions. It is the values on which we operate. So, in the above example, &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt; are &lt;strong&gt;operands&lt;/strong&gt;.&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634696119802%2FopqnLtAOv.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634696119802%2FopqnLtAOv.gif" alt="addition.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are &lt;em&gt;binary&lt;/em&gt; operators, &lt;em&gt;unary&lt;/em&gt; operators, and a &lt;em&gt;ternary&lt;/em&gt; operator in JavaScript. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Binary&lt;/em&gt; operators have two values or operands, that one value comes before the operator, and one comes after the operator. For example, &lt;code&gt;1 + 2&lt;/code&gt; is a binary operator. So &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;2&lt;/code&gt; are the operands, and &lt;code&gt;+&lt;/code&gt; is the operator here. &lt;/p&gt;

&lt;p&gt;There is only one operand in &lt;em&gt;unary&lt;/em&gt; operators. We place the operand before or after the operator.  &lt;code&gt;x++&lt;/code&gt; is an example of the unary operator. We can see only one operand here, which comes before the operator. Don't worry if you don't understand this syntax. Let's come back to this in a later section in this post. &lt;/p&gt;

&lt;p&gt;The &lt;em&gt;ternary&lt;/em&gt; operator has three operands. It is also known as a "conditional" operator.  An example of a ternary operator is &lt;code&gt;age &amp;gt;= 18 ? "can drive" : "can't drive";&lt;/code&gt;. We will dive into ternary operators later in this post.  &lt;/p&gt;

&lt;p&gt;Alright! I hope now you understand what's an operator and what's an operand. You are going to hear these two names many times in this post 😄&lt;/p&gt;

&lt;p&gt;JavaScript supports various operators, and we will be exploring six types of operators, which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arithmetic Operators&lt;/li&gt;
&lt;li&gt;Assignment Operators&lt;/li&gt;
&lt;li&gt;Comparison Operators&lt;/li&gt;
&lt;li&gt;Logical Operators&lt;/li&gt;
&lt;li&gt;Ternary Operators&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;typeof&lt;/code&gt; Operator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, we will learn about Arithmetic and assignment operators, and we will go through the rest in the second part of this series. &lt;/p&gt;

&lt;h2&gt;
  
  
  Arithmetic Operators
&lt;/h2&gt;

&lt;p&gt;We use arithmetic operators to do mathematical operations like addition, subtraction, multiplication, division, etc. It simply takes numerical values as the operands, performs an arithmetic operation, and returns a numerical value. &lt;/p&gt;

&lt;p&gt;Let's look at some of the arithmetic operators in javaScript in the below list. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator Name&lt;/th&gt;
&lt;th&gt;Operator  symbol&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;let x = 10, y = 5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Addition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;+&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Adds two numeric operands.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x + y = 15&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Subtraction&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Subtract right operand from left operand.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x - y = 5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiplication&lt;/td&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Multiply two numeric operands.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x * y = 50&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Division&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Divide left operand by right operand.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x / y = 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Remainder&lt;/td&gt;
&lt;td&gt;&lt;code&gt;%&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Returns remainder of two operands.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x % y = 0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Increment&lt;/td&gt;
&lt;td&gt;&lt;code&gt;++&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Increase operand value by one.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;++x = 11&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Decrement&lt;/td&gt;
&lt;td&gt;&lt;code&gt;--&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Decrease value by one.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;y-- = 5&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exponentiation&lt;/td&gt;
&lt;td&gt;&lt;code&gt;**&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Raise one operand to the power of the other operand.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x ** y = 100000&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now let's see some examples of the above operators.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// 10 + 5 --&amp;gt; 15&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// 10 - 5 --&amp;gt; 5&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// 10 * 5 --&amp;gt; 50&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// 10 / 5 --&amp;gt; 2&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// 10 % 3 --&amp;gt; 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;     &lt;span class="c1"&gt;// 10&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;     &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 5 * 5 * 5 --&amp;gt; 125 &lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Have you noticed that we used two different styles to write increment and decrement operators? Sometimes we used the operator after the operand &lt;code&gt;x++&lt;/code&gt;, sometimes before the operand &lt;code&gt;--y&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;For example, we used &lt;code&gt;x++&lt;/code&gt; in the example above, and the output result was &lt;code&gt;10&lt;/code&gt;. So what happens if we write it as &lt;code&gt;++x&lt;/code&gt;? Then the output result would be &lt;code&gt;11&lt;/code&gt;. Are you confused? Let's find out why this is happening. &lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript prefix and postfix
&lt;/h3&gt;

&lt;p&gt;We can assign the JavaScript increment and decrement operators either before the operand or after the operand. If we assign &lt;code&gt;++&lt;/code&gt; or &lt;code&gt;--&lt;/code&gt; before the operand &lt;code&gt;(++x)&lt;/code&gt;, then we call it "prefix". If we assign it after the operand &lt;code&gt;(x++)&lt;/code&gt;, we call it "postfix". &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using ++/-- After the Operand&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we use the increment/decrement operator after the operand, the operator returns the variable value first, and then only the value will be incremented/decremented by &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's look at the below example to understand this better.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Increment&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      &lt;span class="c1"&gt;// 3&lt;/span&gt;

&lt;span class="c1"&gt;// Decrement&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// 5&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the first values for &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; have the same original value. That's because the original value of the operand is returned before the operand is changed. If you checked the second console log results, which we use the variable the next time, you could see that we get the result including the &lt;code&gt;+1&lt;/code&gt; and &lt;code&gt;-1&lt;/code&gt; values. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using ++/-- Before the Operand&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we use the increment/decrement operator before the operand, It will increment the value of the operand even before returning its value. &lt;/p&gt;

&lt;p&gt;Let's look at the below example to understand this better.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Increment&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      &lt;span class="c1"&gt;// 3&lt;/span&gt;

&lt;span class="c1"&gt;// Decrement&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in the above example, the operation executes the addition and subtraction before returning the value. So you cannot see any difference in each log. This way, it helps us to check the resulting value of an operand instantly. &lt;/p&gt;

&lt;p&gt;Well, now you know how the increment and decrement actually work! &lt;/p&gt;

&lt;p&gt;Before moving into assignment operators, I would like to mention one more use case for the &lt;code&gt;+&lt;/code&gt; operator. &lt;/p&gt;

&lt;h3&gt;
  
  
  Using the &lt;code&gt;+&lt;/code&gt; operator to concatenate strings
&lt;/h3&gt;

&lt;p&gt;You can use the &lt;code&gt;+&lt;/code&gt; operator to combine two or more JavaScript strings into one. The process of combining strings is called JavaScript string concatenation.&lt;/p&gt;

&lt;p&gt;Here is the syntax for the concatenation operator:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;'string1' + 'string2'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's see how this is useful. Let's say that you have two names that you want to combine. One is the first name, and the other is the last name.  Let’s combine these two strings using the &lt;code&gt;+&lt;/code&gt; operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// JohnSmith&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we created two variables for the first and the last name, and we combined the two names with the &lt;code&gt;+&lt;/code&gt; operator to print the full name. &lt;/p&gt;

&lt;p&gt;If you try this code, you will notice that there is no space between the two names. This is because these names are not automatically separated by a space. So if we want to keep a space between, we have to specify it by adding either a space after the first name, or space before the last name, or adding an empty string in between. Check the below example to understand this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Space after the first name&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// John Smith&lt;/span&gt;

&lt;span class="c1"&gt;//Space before the last name&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// John Smith&lt;/span&gt;

&lt;span class="c1"&gt;//Add empty string in between variables&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// John Smith&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634696366488%2FsZBBV-Yi8.jpeg" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634696366488%2FsZBBV-Yi8.jpeg" alt="javascript.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope that is clear! Let's move on to assignment operators 😊&lt;/p&gt;

&lt;h2&gt;
  
  
  Assignment Operators
&lt;/h2&gt;

&lt;p&gt;An assignment operator assigns a value to the left operand based on the value of the right operand. Let's say that we want to assign the value &lt;code&gt;10&lt;/code&gt; to the variable &lt;code&gt;x&lt;/code&gt;. So we use the equal &lt;code&gt;(=)&lt;/code&gt; sign to assign this value, &lt;code&gt;x = 10&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Here's a list of assignment operators in JavaScript:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator Name&lt;/th&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Longform version&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;let x = 5, y = 10&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Assignment&lt;/td&gt;
&lt;td&gt;x = y&lt;/td&gt;
&lt;td&gt;Assigns right operand value to the left operand.&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = 10;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Addition&lt;/td&gt;
&lt;td&gt;x += y&lt;/td&gt;
&lt;td&gt;Sums up left and right operand values and assigns the result to the left operand.&lt;/td&gt;
&lt;td&gt;x = x + y&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x += 10;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Subtraction&lt;/td&gt;
&lt;td&gt;x -= y&lt;/td&gt;
&lt;td&gt;Subtract right operand value from the left operand value and assigns the result to the left operand.&lt;/td&gt;
&lt;td&gt;x = x - y&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x -= 10;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiplication&lt;/td&gt;
&lt;td&gt;x *= y&lt;/td&gt;
&lt;td&gt;Multiply left and right operand values and assigns the result to the left operand.&lt;/td&gt;
&lt;td&gt;x = x * y&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x *= 10;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Division&lt;/td&gt;
&lt;td&gt;x /= y&lt;/td&gt;
&lt;td&gt;Divide left operand value by right operand value and assign the result to the left operand.&lt;/td&gt;
&lt;td&gt;x = x / y&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x /= 10;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Remainder&lt;/td&gt;
&lt;td&gt;x %= y&lt;/td&gt;
&lt;td&gt;Get the remainder of left operand divide by right operand and assign resulted remainder to the left operand.&lt;/td&gt;
&lt;td&gt;x = x % y&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x %= 10;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In the above list, you have seen that we have combined the assignment operator with arithmetic operators, for example, &lt;code&gt;x += 10&lt;/code&gt;. We call these &lt;em&gt;compound assignment operators&lt;/em&gt;. This is a shorthand version to its long-form version, which is &lt;code&gt;x = x + 10&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;It's better to get familiar with these compound assignment operators because you will be using them a lot in the future! 😊&lt;/p&gt;

&lt;p&gt;Now you must be wondering how these expressions should be evaluated when there are multiple operators in the same expression. &lt;/p&gt;

&lt;p&gt;For example, let's look at the below expression. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;(2 + 3) * 5 = ?&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's see how JavaScript understands which part of this mathematical expression should be evaluated first. &lt;/p&gt;

&lt;h2&gt;
  
  
  Operator Precedence
&lt;/h2&gt;

&lt;p&gt;If you remember your arithmetic lessons, you might remember the acronym P.E.M.D.A.S (Please Excuse My Dear Aunt Sally). This acronym PEMDAS helps us to remember which part of our mathematical expression should be evaluated first.&lt;/p&gt;

&lt;p&gt;First, we work with what is inside the parenthesis, next exponents, then multiplication, then division, after that addition, and the last subtraction.&lt;/p&gt;

&lt;p&gt;So if we take the example, &lt;code&gt;(2 + 3) * 5 = ?&lt;/code&gt;, since the &lt;code&gt;2 + 3&lt;/code&gt; is within parenthesis, we add these two numbers together, which gives us &lt;code&gt;5&lt;/code&gt;. Then we take that result of &lt;code&gt;5&lt;/code&gt; and multiply it by &lt;code&gt;5&lt;/code&gt;. So the final result is &lt;code&gt;25&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So in JavaScript, we have the same way of evaluating expressions with well-defined operator precedence. &lt;/p&gt;

&lt;p&gt;You can use the  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence" rel="noopener noreferrer"&gt;MDN document&lt;/a&gt; to check the operator precedence table. The MDN document has listed down all the operators with their precedence and associativity.&lt;/p&gt;

&lt;p&gt;If you wonder what the meaning of associativity is, it tells us the direction of evaluating the expression. For example, if you look at the table on the MDN document, you can see that under the associativity column, it tells us the direction ( ‘left to right’ ) for some operators. This is very helpful when two operators have the same level of precedence.&lt;/p&gt;

&lt;p&gt;We have &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt; in the same expression, then the expression is evaluated left to right. Let's check the below examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 6&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the first expression first calculates the &lt;code&gt;5 + 3&lt;/code&gt;, and then &lt;code&gt;2&lt;/code&gt; is subtracted from that result. So it does the calculation from left to right. The second expression evaluates in the same way. &lt;/p&gt;

&lt;p&gt;You don't have to remember each and every operator's precedence by heart, but having a strong understanding of how the precedence works is crucial for your programming journey. &lt;/p&gt;

&lt;p&gt;Alright, that's it for the day! 🤗&lt;/p&gt;

&lt;p&gt;I hope now you have a good understanding of Arithmetic operators, assignment operators, and operator precedence.&lt;/p&gt;

&lt;p&gt;In the second part of this two-part series, we will be going over the following operators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Comparison Operators&lt;/li&gt;
&lt;li&gt;Logical Operators&lt;/li&gt;
&lt;li&gt;Ternary Operators&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;typeof&lt;/code&gt; Operator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Until that, you can check out this JavaScript operators cheatsheet 😊&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634819327165%2FvE9vrNwmf.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634819327165%2FvE9vrNwmf.png" alt="Screenshot 2021-10-21 at 17.57.32.png"&gt;&lt;/a&gt;&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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634697373133%2FjgPGVQlyr.gif" 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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1634697373133%2FjgPGVQlyr.gif" alt="see-ya.gif"&gt;&lt;/a&gt;&lt;/p&gt;






&lt;p&gt;&lt;a href="https://dasha.ai/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F75135110%3Fs%3D50%26v%3D4" alt="Visit Dasha AI"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Join  &lt;a href="https://community.dasha.ai/" rel="noopener noreferrer"&gt;Dasha Developer Community&lt;/a&gt; where you’ll meet welcoming like-minded developers who share ideas, questions, and get all the help they need to build cool conversational AI apps (for free, of course).&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
