• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Short-Circuit Evaluation Using &&

Short-Circuit Evaluation Using &&

Short-Circuit Evaluation Using &&

Instead of having to check if something is true with an if statement, you can use the && operator:

var isReady = true;

function doSomething(){
  console.log("Yay!");
}

// LONGER FORM
if(isReady){
  doSomething();
}

// SHORTHAND
isReady && doSomething();

Source

https://medium.com/geekculture/20-javascript-snippets-to-code-like-a-pro-86f5fda5598e

Miscellaneous

Related Snippets:

  • Remove an attribute from an element
  • Create a one time event handler
  • Get Siblings of an Element
  • How To Check If a Variable is a String in JavaScript

Primary Sidebar

JSON Compare

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers