<?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: José M. Gilgado</title>
    <description>The latest articles on DEV Community by José M. Gilgado (@jose).</description>
    <link>https://dev.to/jose</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%2F232775%2Ff50ac777-97f4-4096-bba1-bc2d0fe60893.png</url>
      <title>DEV Community: José M. Gilgado</title>
      <link>https://dev.to/jose</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jose"/>
    <language>en</language>
    <item>
      <title>How to be a better remote worker</title>
      <dc:creator>José M. Gilgado</dc:creator>
      <pubDate>Tue, 15 Oct 2019 15:44:52 +0000</pubDate>
      <link>https://dev.to/jose/how-to-be-a-better-a-remote-worker-18gn</link>
      <guid>https://dev.to/jose/how-to-be-a-better-a-remote-worker-18gn</guid>
      <description>&lt;p&gt;The current scene, with so many companies working remotely, leaves the employees with some changes in how things work in a company when there's no office that are not obvious. Dynamics, habits and workflows change to some extent in a remote organization.&lt;/p&gt;

&lt;p&gt;In this article, I share some of the things I've learnt in the last few years that helped me from the perspective of a regular employee in a fully remote company (Buffer). Let's start!&lt;/p&gt;

&lt;h2&gt;
  
  
  Open communication by default
&lt;/h2&gt;

&lt;p&gt;How do you know if your teammate is blocked? Or if you're a manager that you're happy with somebody's performance. How does the team lead know what's the current status of a project?&lt;/p&gt;

&lt;p&gt;These questions, as necessary as they are, are hard to answer in a remote company since they're usually answered over coffee or just by physically walking to the other person's desk if you work in an office. When you work remotely, you need to actively think about giving them their space.&lt;/p&gt;

&lt;p&gt;By working remotely you need to change your mindset and communicate by default all you do and how you are feeling with your current workload/team/schedule. Yes, this will have an impact on your time available for other things but on the other side you shouldn't have too many interruptions. How should do this?&lt;/p&gt;

&lt;p&gt;Any format is good as long as is easy to use and transparent to the rest of your team. There are teams that do daily asynchronous standup, others keep track of everything in a tool like Jira or Trello. It's up to you but you need to communicate way more than in a regular company. Some tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Have you made progress in a task? Leave an update in the card.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Are you blocked or feeling that the current task is too hard? Reach out as soon as possible and ask for help.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have you found something unexpected that might delay the whole project? Prepare a quick document with the context and share it with the team.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Have you had an idea on how to improve something? You know the drill 😉.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The alternative to this "over-communication" are isolated teams and team members, no transparency with stakeholders, not knowing where things are and how far you're with a project and an overall feeling that the team or full company is not driven towards a particular direction and everyone is just doing their own thing.&lt;/p&gt;

&lt;p&gt;Try to think who might be interested in knowing something, how much they know and how to share that as clearly as possible. This also implies that sometimes you might need to communicate the same thing more than once. For example, if I've just completed a task I might share:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The full context of the technical details with my teammates if it's interesting because maybe I refactored something.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The current status with the product manager and the designer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The change that this will bring and potential issues customers might find with the customer support team.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In each case, the context I'll provide and the information will be focus on what those people know. The refactoring part probably doesn't matter to the customer support team for example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your schedule is yours and yours only
&lt;/h2&gt;

&lt;p&gt;Use it to your advantage. I've started working sometimes at 4:30 AM because I was feeling great and finished that day earlier too. I was more productive and had more quiet time before the rest of my team woke up.&lt;/p&gt;

&lt;p&gt;Some days I knew I had a couple of calls in the evening so I spent the first few hours of the day working out or doing something else.&lt;/p&gt;

&lt;p&gt;The key here is finding that balance because for the most part you won't have anyone telling you need to work from 9 to 5. In a remote company, your output is way more important than the hours you put in. As long as you perform well you should be ok.&lt;/p&gt;

&lt;p&gt;This also applies to your workspace, try different things and see what works better for you, it might be a co-working space, an occasional walk to your favorite coffee shop, it's up to you but try different things and see how it feels.&lt;/p&gt;

&lt;h2&gt;
  
  
  You're not alone, help others
&lt;/h2&gt;

&lt;p&gt;In my experience, it's much easier to isolate yourself working on your own thing, or even not collaborating with almost anyone if it's not strictly required. At the end of the day, you're mainly focus on your output so it's easy to forget that you have the chance to learn and collaborate with your teammates. Some actions could be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Send a message in your team channel or email group if you need help.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reach out to one of your teammates at your level of experience to chat about vision, strategies to improve or a new book you've read that it's influencing the way you work.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  If something feels off, say it
&lt;/h2&gt;

&lt;p&gt;Or, as the old saying goes, give feedback 😊. I'd say this is equally important in an office but in a remote environment is slightly harder, you need to actively reach out to someone to share it, it doesn't happen casually over coffee.&lt;/p&gt;

&lt;p&gt;Depending on the kind of company you're working, you might need to adjust this or be more or less direct. Some companies love feedback at every level and others don't but if you have the chance, sharing feedback early and often it's a great exercise to improve as a professional and you're opening the door to some feedback for you, which is even better.&lt;/p&gt;

&lt;p&gt;It'll feel odd at first, it's hard to give and even harder to receive feedback but there's no other way to know that what you or others are doing can be better.&lt;/p&gt;

&lt;p&gt;Some tools that helps in the company I work for, Buffer, are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Anonymous link that we all have to share feedback anytime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Q&amp;amp;A with the CEO and leaders every month or so where you can submit questions anonymously (or signed).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Anonymous survey every quarter from the company.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Retro sessions where we can share how we feel in our team and what we could improve.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A general culture of welcoming feedback.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key realization about feedback for me was that it's not about you, your ego, your work culture or anything like that, it's just about a specific action that you did or didn't do and where you can improve next time. It's only that, don't make it bigger.&lt;/p&gt;

&lt;h2&gt;
  
  
  Be creative and proactive
&lt;/h2&gt;

&lt;p&gt;When you're in an office, ideas flow all the time. People talk about ideas, ways to improve things, something they've read about another company that's great and they could use, etc.&lt;/p&gt;

&lt;p&gt;When you're working remotely, you tend to focus much more on the task at hand so it's very important to take a step back from time to time and come up with some ways to improve things that might be different from what you've been doing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When was the last time you took a couple of hours to think and plan? Make it a habit. Every x days, book some time off and do it. Paper, drawings, a whiteboard or even a walk in the nearest park with a notebook can help.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Share ideas early and often. Also related to the open communication you need to maintain, but in this case it's a great way to invite others to work on new things that will improve the company. Be specific with the kind of feedback you want to receive from the people you ask, are you asking for approval, real feedback or it's just FYI? Be sure to mention that with the people you share it. For example, for other teammates in another team something might be FYI but for my CTO or closer teammates I want their real feedback on an idea.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Innovation comes from different places, expose yourself to new ideas. Books, conferences, chats with other people in the industry, tweets!, podcasts, videos... the list is big and you don't know where the next good idea might come from. Make sure you read/watch/listen some different people and companies to get new ideas that you can try.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Find a mentor
&lt;/h2&gt;

&lt;p&gt;If you have someone you admire, or someone you feel you can learn a lot from, talk to that person often and ask them questions. A mentor-mentee relationship doesn't have to be anything formal or official and you can have multiple people you respect, in or outside your company, that you can learn from. Use that to get more knowledge, improve, ask questions, learn from the same sources they learn and you'll see a lot of improvement soon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Align with the team or company's goals
&lt;/h2&gt;

&lt;p&gt;These goals are usually shared transparently and they're a very good indicator of what's most important at this point for your team or the company.&lt;/p&gt;

&lt;p&gt;They might be focus on growth, quality, scaling the team by hiring and mentoring new people, pivot to another product or industry, etc. You'll soon discover in your career that almost all the software companies share the same problems, they only vary in degree.&lt;/p&gt;

&lt;p&gt;Make those goals your goals as well and try to come up with ways on how you can contribute. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Is the company hiring a lot? Volunteer to onboard those new teammates or even interviewing new candidates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is the focus on growth? Try to come up with some ideas to improve your and your team's effectiveness when working. It could automated tests, a CI system with a quick deploy process or better flows to communicate changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is the company pivoting to another product/industry? Go ahead and discover people in your position working in those products. What do they know? How do they work? What are their main challenges? Anticipate to those questions in your company and bring solutions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Focus on one thing at a time and one thing only
&lt;/h2&gt;

&lt;p&gt;Constantly ask yourself, what's the most important and impactful thing I could be doing and then go ahead and only focus on that until you finish it.&lt;/p&gt;

&lt;p&gt;Make that reflection a habit, a daily, weekly, quarterly one. There are big things and small things. Mentoring other people is a big thing, solving a problem that's affecting and delaying other engineers is a small one but both could be equally important depending on the situation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Focus on the things that don't change
&lt;/h2&gt;

&lt;p&gt;Jeff Bezos famously shared that Amazon actively focuses on the things that don't change even if it's in the long term. You won't want to wait longer in the future for a package, or have less products on Amazon so can't buy what you need, or have a slower website where you can buy products. If you focus on improving those things, customers will appreciate it and buy more from you.&lt;/p&gt;

&lt;p&gt;There's a great exercise you can make with that idea: &lt;strong&gt;think about the aspects of your product or workflow that won't change in the future and whose constant improvement will always bring benefits to the team&lt;/strong&gt;. You don't need to be in a high level position for doing this, you don't need to be the CEO or CTO of that company, even a junior software engineer or manager can contribute with this approach.&lt;/p&gt;

&lt;p&gt;Here are some challenging questions that helped me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How long does it take to load your main product's site?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you know if something fails in your product?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How long does it take from idea to execution in your team if the idea is great?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is there a way to automatize that little thing you need to do almost daily? What would be the impact in a week if you and each of your teammates could save 5 minutes on a daily basis? And in a month? What about in a year?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From the X hours you work every day, would there be a way to come up with a schedule that makes you more efficient?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do you need to explain that little thing that's particular to the project every time or could you just create a written resource so others won't need to ask next time?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After some time working there, if you started again in the company tomorrow, what are the things you'd like to have to be more productive from day one? Could you help creating those resources for the new people that will come?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do you have some annoying things that fail from time to time but haven't fixed yet? How much is that delaying you and your teammates? How is that affecting your motivation?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Other ideas?
&lt;/h2&gt;

&lt;p&gt;Do you have other ideas that have helped you? Reach out on &lt;a href="https://twitter.com/jmgilgado"&gt;Twitter&lt;/a&gt;! 🙂&lt;/p&gt;

</description>
      <category>career</category>
      <category>remote</category>
    </item>
    <item>
      <title>Intro to bitwise operations</title>
      <dc:creator>José M. Gilgado</dc:creator>
      <pubDate>Wed, 09 Oct 2019 13:39:47 +0000</pubDate>
      <link>https://dev.to/jose/intro-to-bitwise-operations-3ik3</link>
      <guid>https://dev.to/jose/intro-to-bitwise-operations-3ik3</guid>
      <description>&lt;p&gt;Bitwise operations are really useful and fast for storing and operate on certain values. They are way more used in systems where resources are more limited like video-games or embedded devices.&lt;/p&gt;

&lt;p&gt;In this first article about bitwise operations, we get a quick introduction to them with a drawing (new format!) and some written content but I plan on sharing more 🙂.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are bitwise operations?
&lt;/h2&gt;

&lt;p&gt;They're operations that deal with bits directly. Bits are 1s and 0s and it's how everything is stored internally in a computer so being able to operate with them directly is very efficient because the processor is able to do those operations natively. &lt;a href="https://en.wikipedia.org/wiki/Bitwise_operation"&gt;Wikipedia says&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;...typically, bitwise operations are substantially faster than division, several times faster than multiplication, and sometimes significantly faster than addition...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The three basic operators
&lt;/h2&gt;

&lt;p&gt;There are more but let's take a look today at the three most basic operators:&lt;/p&gt;

&lt;h3&gt;
  
  
  NOT
&lt;/h3&gt;

&lt;p&gt;NOT is very simple, if there's a 1 we get 0. If there's a 0, we get 1.&lt;/p&gt;

&lt;p&gt;It's represented by &lt;em&gt;~&lt;/em&gt; in most programming languages so for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~0101011 = 1010100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  AND
&lt;/h3&gt;

&lt;p&gt;AND is like the boolean equivalent you already use in if conditions but with one difference, this operates at the level of bits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  OR
&lt;/h3&gt;

&lt;p&gt;The same goes for the OR operation, represented with the | symbol in many programming languages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How they operate with more than 1 bit
&lt;/h2&gt;

&lt;p&gt;The key here is to remember that when we have a bitwise operation with more than 1 bit, we do it bit by bit. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Bitwise OR&lt;/span&gt;
&lt;span class="mi"&gt;111010&lt;/span&gt;
&lt;span class="mo"&gt;001100&lt;/span&gt;
&lt;span class="o"&gt;-------&lt;/span&gt;
&lt;span class="mi"&gt;111110&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or in an AND operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Bitwise AND&lt;/span&gt;
&lt;span class="mi"&gt;111010&lt;/span&gt;
&lt;span class="mo"&gt;001100&lt;/span&gt;
&lt;span class="o"&gt;-------&lt;/span&gt;
&lt;span class="mo"&gt;001000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Real life example:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1310LOVq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://josemdev.com/images/intro-bitwise.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1310LOVq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://josemdev.com/images/intro-bitwise.png" alt="Intro to bitwise" title="Intro to bitwise"&gt;&lt;/a&gt;&lt;br&gt;
&lt;span class="photo-credit"&gt;&lt;a href="https://josemdev.com/images/intro-bitwise-full.png"&gt;Full drawing here&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
In a future article we'll see other operators because you can do some very efficient calculations with numbers but we need more than just these three. See you soon!&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>bitwise</category>
    </item>
    <item>
      <title>CS Basics: How to refactor a boolean expression</title>
      <dc:creator>José M. Gilgado</dc:creator>
      <pubDate>Wed, 25 Sep 2019 16:20:43 +0000</pubDate>
      <link>https://dev.to/jose/cs-basics-how-to-refactor-a-boolean-expression-4pja</link>
      <guid>https://dev.to/jose/cs-basics-how-to-refactor-a-boolean-expression-4pja</guid>
      <description>&lt;h1&gt;
  
  
  Intro to series
&lt;/h1&gt;

&lt;p&gt;Computer Science sounds so boring, so academic, that sometimes it's hard to know if there's even any useful knowledge for our jobs building actual software.&lt;/p&gt;

&lt;p&gt;Of course, I'm half joking. Computer Science is very important to understand what's going on in a computer but I understand it doesn't sound as attractive as learning a specific technology that's in demand in the industry.&lt;/p&gt;

&lt;p&gt;With this series of posts, I'll try to extract from those long boring books a few things we can start applying right away and I hope you'll find useful.&lt;/p&gt;

&lt;p&gt;I'll always start with the immediate practical part and then I'll explain a bit more about the underlying reasons and terminology.&lt;/p&gt;

&lt;p&gt;Let's start today with some boolean expressions.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why is it useful to refactor a boolean expression?
&lt;/h1&gt;

&lt;p&gt;It has happened to me many times that, when refactoring a condition, I had to change it to create a method that makes sense in the class. Let's show an simple example.&lt;/p&gt;

&lt;p&gt;Imagine we have the following class (in Javascript, but can be applied to almost any language):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;hasEmail&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;isActive&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;sendEmail&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="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// ... send email ...&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At some point we realize that it might be easier to have an internal method that can tell us if the user can receive emails. According to the code that'd mean that it's an active user and has an email set.&lt;/p&gt;

&lt;p&gt;We could do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;  &lt;span class="nf"&gt;canReceiveEmail&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="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// What do we return here? 🤔&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;sendEmail&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="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;canReceiveEmail&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the &lt;em&gt;sendEmail&lt;/em&gt; method is more readable now, &lt;strong&gt;but what should we put in the &lt;em&gt;canReceiveEmail()&lt;/em&gt; method&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;I'll let you think for a second...🙂&lt;/p&gt;

&lt;p&gt;🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔&lt;/p&gt;

&lt;p&gt;🤔🤔🤔🤔🤔🤔🤔🤨🐶🤨🤔🤔🤔🤔🤔🤔🤔🤔&lt;/p&gt;

&lt;p&gt;🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Did you figure it out?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What we need is the opposite value of the condition we had:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The negation of that expression would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I think intuitively we can understand that if what we were looking for is that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user is not active &lt;em&gt;OR&lt;/em&gt; doesn't have email;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The opposite would be that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user is active &lt;em&gt;AND&lt;/em&gt; has email.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the final class would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;hasEmail&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;isActive&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;canReceiveEmail&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;sendEmail&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="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;canReceiveEmail&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// Notice negation of the method with !&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// ... send email ...&lt;/span&gt;
  &lt;span class="p"&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;span&gt;&lt;a href="https://jsbin.com/lusafuv/edit?js,console" rel="noopener noreferrer"&gt;(see in JSbin)&lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;We could also have created the negative version &lt;em&gt;cannotReceiveEmail&lt;/em&gt; but I prefer to use "positive" method names since they tend to be more useful in other places of the code. Nevertheless, If we had done that the result would have been:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;cannotReceiveEmail&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="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;sendEmail&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cannotReceiveEmail&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// ... send email ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Computer Science behind solution
&lt;/h1&gt;

&lt;p&gt;What you just saw wasn't discovered recently, the mathematician who formulated this solution, Augustus De Morgan, died in 1871.&lt;/p&gt;

&lt;p&gt;This rule, along with another one we'll see in a bit, are called "De Morgan's Laws". They're part of a bigger field in Mathematics and studied in any computer science course, called Boolean Algebra.&lt;/p&gt;

&lt;p&gt;The other rule is as follows. If we have this expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;willDieSoon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isYoung&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;worksOut&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;willDieSoon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isYoung&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;worksOut&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you didn't get this one, think about what would happen in all the potential conditions:&lt;/p&gt;

&lt;p&gt;Consider &lt;em&gt;isYoung&lt;/em&gt; is true/false and &lt;em&gt;worksOut&lt;/em&gt; is true/false. What would be the result of the expression? Wouldn't that be the same that in the first case?&lt;/p&gt;

&lt;p&gt;To truly understand this, it's often useful to create a small table of possibilities. The last column represents: &lt;em&gt;willDieSoon&lt;/em&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;em&gt;isYoung&lt;/em&gt;&lt;/th&gt;
&lt;th&gt;&lt;em&gt;worksOut&lt;/em&gt;&lt;/th&gt;
&lt;th&gt;&lt;em&gt;isYoung OR worksOut&lt;/em&gt;&lt;/th&gt;
&lt;th&gt;&lt;em&gt;!(isYoung OR worksOut)&lt;/em&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The same table can be applied to the first expression:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;em&gt;isYoung&lt;/em&gt;&lt;/th&gt;
&lt;th&gt;&lt;em&gt;worksOut&lt;/em&gt;&lt;/th&gt;
&lt;th&gt;&lt;em&gt;!isYoung AND !worksOut&lt;/em&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  The Morgan's Laws
&lt;/h2&gt;

&lt;p&gt;So the two rules, written in a formal manner, would be:&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%2Fjosemdev.com%2Fimages%2Fmorgan_laws.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%2Fjosemdev.com%2Fimages%2Fmorgan_laws.png" title="De Morgan's Laws" alt="De Morgan's Laws"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This image is from Wikipedia since I'm not sure how to add math symbols in dev.to 😞.&lt;/p&gt;

&lt;p&gt;So in Javascript, we could say this is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;Q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;Q&lt;/span&gt;

&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;Q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;Q&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've used the second one to refactor our code.&lt;/p&gt;

&lt;p&gt;We started with the &lt;em&gt;!P || !Q&lt;/em&gt; and ended with &lt;em&gt;!(P &amp;amp;&amp;amp; Q)&lt;/em&gt;. Let's review it now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// we started with this condition to check before sending the email:&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// Then, we moved the logic to canReceiveEmail()&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// And used the negation of that:&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;canReceiveEmail&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;// Which is:&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isActive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasEmail&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="c1"&gt;// So:&lt;/span&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;Q&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;B&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Other Boolean Algebra Laws
&lt;/h2&gt;

&lt;p&gt;If you didn't know about this boolean algebra laws specifically, don't worry! You're probably applying others like:&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%2Fjosemdev.com%2Fimages%2Fcommutativity.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%2Fjosemdev.com%2Fimages%2Fcommutativity.png" title="Commutativity" alt="Commutativity"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those mean that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;weAreInChrome&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nf"&gt;weAreInFirefox&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;weAreInFirefox&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nf"&gt;weAreInChrome&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isRaining&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;isCloudy&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isCloudy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;isRaining&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, intuitively perhaps, you know that the boolean conditions with two values can be switched in order and the result is the same (🤓🗯️ &lt;em&gt;that's commutativity!&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;There are &lt;a href="https://en.wikipedia.org/wiki/Boolean_algebra#Laws" rel="noopener noreferrer"&gt;many others boolean laws&lt;/a&gt; that are useful so I might do a second part of boolean logic later in the series with the ones that are not so intuitive.&lt;/p&gt;

&lt;p&gt;Did you find this one useful? Let me know &lt;a href="https://twitter.com/jmgilgado" rel="noopener noreferrer"&gt;on Twitter&lt;/a&gt; please! 👋 🙂&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Boolean_algebra" rel="noopener noreferrer"&gt;Boolean Algebra&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/De_Morgan%27s_laws" rel="noopener noreferrer"&gt;De Morgan's laws&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>computerscience</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Better Console Debug in Javascript</title>
      <dc:creator>José M. Gilgado</dc:creator>
      <pubDate>Thu, 19 Sep 2019 14:04:34 +0000</pubDate>
      <link>https://dev.to/jose/better-console-debug-in-javascript-48b4</link>
      <guid>https://dev.to/jose/better-console-debug-in-javascript-48b4</guid>
      <description>&lt;p&gt;When debugging an object in Javascript, you usually do something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or even:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;debug&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we create the object with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you do a console.debug from somewhere in the code, in the console you'll see:&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%2Fjosemdev.com%2Fimages%2Fbetter-console-debug-js.png" class="article-body-image-wrapper"&gt;&lt;img alt="" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjosemdev.com%2Fimages%2Fbetter-console-debug-js.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So it might not be clear which object you're dealing with. To solve this you can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;debug&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is the name of the object and the full object printed:&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%2Fjosemdev.com%2Fimages%2Fbetter-console-debug-js-2.png" class="article-body-image-wrapper"&gt;&lt;img alt="" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjosemdev.com%2Fimages%2Fbetter-console-debug-js-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This comes from ES6, it's usually called &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Property_definitions" rel="noopener noreferrer"&gt;shorthand property names&lt;/a&gt; and it works because the key and the object variable has the same name.&lt;/p&gt;

&lt;p&gt;It's the same thing that saying:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;debug&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But more convenient as you can see. 😉&lt;/p&gt;

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