As title
As I know
(if this part is true) && (this part will execute)
if(condition){
(this part will execute)
}
0 is false, so why not echo false but 0?
1. Binary is a base-2 number system invented by Gottfried Leibniz that's made up of only two numbers or digits: 0 (zero) and 1 (one). This numbering system is the basis for all binary code, which is used to write digital data such as the computer processor instructions used every day.
Zero is the integer denoted 0 that, when used as a counting number, means that no objects are present. It is the only integer (and, in fact, the only real number) that is neither negative nor positive. A number which is not zero is said to be nonzero. A root of a function is also sometimes known as "a zero of ."
The Definition of a Zero Factorial This still counts as a way of arranging it, so by definition, a zero factorial is equal to one, just as 1! is equal to one because there is only a single possible arrangement of this data set.
Because operator &&
return first falsey element otherwise they return last element
1 && 0 && false // 0
1 && 2 && 3 // 3
From MDN:
expr1 && expr2 -- Returns expr1 if it can be converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.
expr1 || expr2 -- Returns expr1 if it can be converted to true; otherwise, returns expr2. Thus, when used with Boolean values, || returns true if either operand is true.
!expr -- Returns false if its single operand can be converted to true; otherwise, returns true.
Some expressions that can be converted to false are:
Short-circuit evaluation
As logical expressions are evaluated left to right, they are tested for possible "short-circuit" evaluation using the following rules:
The JavaScript documentation of logical operators explains:
Logical operators are typically used with
Boolean
(logical) values. When they are, they return aBoolean
value. However, the&&
and||
operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean
values, they may return a non-Boolean
value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With