Reasons for this question
- Python is a programming language that has a very interesting philosophy... Called The Zen of Python. On this, does Javascript have a philosophy just like Python... as The Zen of Javascript?
- In Python philosophy there is something like the law "Explicit is better than implicit." Why doesn't JavaScript have explicit words for logical operations? What is the philosophy behind javascript?
- My goal in this question is to know a curious fact ... my goal is not to criticize JavaScript ... but know which philosophy behind JavaScript ...
- I didn't eat information about it
Some examples...
case 1: or
case1.1: example1.js
alert( true || true ); // true
alert( false || true ); // true
alert( true || false ); // true
alert( false || false ); // false
case1.2: example2.js
alert( true or true ); // true
alert( false or true ); // true
alert( true or false ); // true
alert( false or false ); // false
case2.1: example1.js
result = a || b;
case2.2: example2.js
result = a or b;
case3.1: example1.js
if (1 || 0) { // works just like if( true || false )
alert( 'truthy!' );
}
case3.2: example2.js
if (1 or 0) { // works just like if( true || false )
alert( 'truthy!' );
}
case 2: and
case1.1: example1.js
alert( true && true ); // true
alert( false && true ); // false
alert( true && false ); // false
alert( false && false ); // false
case1.2: example2.js
alert( true and true ); // true
alert( false and true ); // false
alert( true and false ); // false
alert( false and false ); // false
case 3: not
case1.1: example1.js
alert( !true ); // false
alert( !0 ); // true
case1.2: example2.js
alert( not true ); // false
alert( not 0 ); // true