Does JavaScript have “Short-circuit” evaluation?
问题 I would like to know if JavaScript has "short-circuit" evaluation like && Operator in C#. If not, I would like to know if there is a workaround that makes sense to adopt. 回答1: Yes, JavaScript has "short-circuit" evaluation. if (true == true || foo.foo){ // Passes, no errors because foo isn't defined. } Live DEMO if (false && foo.foo){ // Passes, no errors because foo isn't defined. } Live DEMO 回答2: This answer goes into great detail on how short-circuiting works in JavaScript, with all the