DEV Community


Discussion on: How to Shorten JavaScript Conditionals with Short-Circuiting

reedbarger profile image
Reed Barger Author

"As the name suggests, short-circuiting is a way we can shorten unnecessary checks in our conditionals by making use of some special tricks in the JavaScript language."

airmind profile image
Alex Ágreda

I think what Jon meant, Reed, was the missing part of explaining those "special tricks".

That JS will not check the "second" part of a || expression because the first one being true is enough to return true, and a && expression will always need to check the "second" part because it need both to be true to return true

Thread Thread
jonrandy profile image
Jon Randy • Edited

Also explaining that expression evaluation will completely stop i.e. further function calls in the expression after the short circuit will not occur. This is not the same in all languages. Some do not have short circuit evaluation