Short-circuits conditionals

Updated at 25-Sep-2021, By samar

Short-circuits conditionals

Through the use of the programming language, we will work together to solve the "Short-circuits conditionals" puzzle in this lesson.

Short-circuits conditionals method uses the && operator and It will call the second operand and return output if condition is true. In case if condition is false then it will return false as output.
  • Get double using arraw function with short-circuits conditional

    <script>
    //Syntax
    condition && do()
    
    //Code snippet
    const getDouble = (val) => { return val + val  }
    let online = true;
    let data = online && getDouble(20);
    console.log(data); 
    </script>
    

    Output :

    40

    Short circuiting means that in JavaScript when we are evaluating an AND expression (&&), if the first operand is false, JavaScript will short-circuit and not even look at the second operand

Back to code snippet queries related javascript