JavaScript (main.js):
function foo() {
console.log('Hello');
return true;
}
function bar() {
console.log('World');
return false;
}
foo() && bar(); //Hello World
bar() && foo(); //World
foo() || bar(); //Hello
bar() || foo(); //World Hello
說明:
1. foo()為true 則會繼續執行bar()
2. bar()為false不會繼續執行foo()
3. foo()為true 不會繼續執行bar()
4. bar()為false則會繼續執行foo()
沒有留言:
張貼留言