Skip to content

Short-circuit evaluation and return for && || #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Javascript/2-logical-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ console.log('Mix of Tea AND Juice is ' + goodDrinks);
console.log('Mix of Vodka AND Beer is ' + badDrinks);
console.log('Mix of Vodka AND Juice is ' + badMix);

const logicalAndFirstFalse = 'string' && 0 && 10; // 0
console.log('\'string\' && 0 && 10 => ' + logicalAndFirstFalse);

const logicalAndLastTrue = 'string' && 5 && 10; // 10
console.log('\'string\' && 5 && 10 => ' + logicalAndLastTrue);

const engine1 = true;
const engine2 = false;

Expand All @@ -27,6 +33,12 @@ console.log('The first engine works? - ' + engine1);
console.log('The second engine works? - ' + engine2);
console.log('Is the plane still flying? - ' + fly);

const logicalOrFirstTrue = 'string' || 0 || 10; // 'string'
console.log('\'string\' || 0 || 10 => ' + logicalOrFirstTrue);

const logicalOrLastFalse = '' || null || 0; // 0
console.log('\'\' || null || 0 => ' + logicalOrLastFalse);

const happy = true;

const mood = !happy; // false
Expand Down