Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript ternary operator calling function or no-op

Tags:

javascript

What is best practice for debugging in JavaScript?

debugging ? console.log('info') : null;

My question is the null, what is standard practice for this in general, or in this debugging use case?

like image 986
Mark Robbins Avatar asked Dec 20 '22 05:12

Mark Robbins


1 Answers

In your case:

debugging && console.log('info');

This trick is based on the "short circuit" feature and I suppose this info might be useful: http://en.wikipedia.org/wiki/Short-circuit_evaluation

like image 79
Vladimir Posvistelik Avatar answered Jan 14 '23 09:01

Vladimir Posvistelik