Multi-Tasking

worker counting stocks in warehouse

There are times in programming where you need to check conditions against multiple items. If statements are used to do this a lot. We could do this by nesting if statements and performing the code if they return true as follows…

if(this === that){
    if(who === what){
        doSomething();
    }
}

While this works, nesting can get hairy and confusing. There is a way that could be simpler. We can use the and (&&) operator to check two conditions. Here is a revision of the previous code…

if(this === that && who === what){
    doSomething();
}

The previous example shows how to compare two separate condition statements, but you can put together multiple conditions.

On a related note, you can also use the or (||) operator to utilize either/or logic.

Happy Coding!

Clay Hess

More To Explore

Developer working with styles at a coffeehouse with code swirling around him
Code

The CSS Object Model (CSSOM): A Practical Guide

If you’ve ever used JavaScript to read or modify styles in the browser, you’ve touched the CSS Object Model—often without realizing it. The CSSOM sits

Share This Post

small_c_popup.png

Need help?

Let's have a chat...


Login

Jump Back In!

Here at Webolution Designs, we love to learn. This includes sharing things we have learned with you. 

Register

Begin Your Learning Journey Today!

Come back inside to continue your learning journey.