Skip to content

Instantly share code, notes, and snippets.

@cms
Created September 8, 2010 07:39
Show Gist options
  • Save cms/569777 to your computer and use it in GitHub Desktop.
Save cms/569777 to your computer and use it in GitHub Desktop.
BESEN wrong behavior of the logical && and || operators
// BESEN wrong behavior of the logical && and || operators
// Tested on r111
var obj = {};
// Logical AND operator
print(obj && obj); // prints true, expected '[object Object]'
print(obj && 'foo'); // prints '[object Object]', expected 'foo'
print(obj && 4); // prints '[object Object]', expected 4
print(obj && NaN); // prints false, expected NaN
print(NaN && 0); // prints 0, expected NaN
print(NaN && NaN); // prints false, expected NaN
print(obj && true); // prints false, expected true
print(obj && undefined); // prints false, expected undefined
print(obj && null); // prints false, expected null
print(obj && false); // prints false, Ok
print(obj && 0); // prints 0, Ok
// Logical OR operator
print(obj || obj); // prints true, expected '[object Object]'
print(obj || 'foo'); // prints 'foo', expected '[object Object]'
print(obj || 4); // prints '4', expected '[object Object]'
print(obj || NaN); // prints true, expected '[object Object]'
print(NaN || 0); // prints NaN, expected 0
print(NaN || NaN); // prints false, expected NaN
print(obj || true); // prints true, expected '[object Object]'
print(obj || undefined); // prints true, expected '[object Object]'
print(obj || null); // prints true, expected '[object Object]'
print(obj || 0); // prints '[object Object]', Ok
print(obj || false); // prints [object Object], Ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment