loading...

re: How to Shorten JavaScript Conditionals with Short-Circuiting VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Good explanation of how to use it to shorten code, but missing the explanation of what short-circuiting actually is, and why it's called that (it's...
 

"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."

 

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

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

code of conduct - report abuse