Why does hello 0 return TRUE?
Because 0
is coerced to "0"
. See help(">")
:
If the two arguments are atomic vectors of different types, one is
coerced to the type of the other, the (decreasing) order of
precedence being character, complex, numeric, integer, logical and
raw.
Why does (0 == 'Hello') return true in PHP?
The operators ==
and !=
do not compare the type. Therefore PHP automatically converts 'Hello' to an integer which is 0
(intval('Hello')
). When not sure about the type, use the type-comparing operators ===
and !==
. Or better be sure which type you handle at any point in your program.
Why does function sometimes return 0 and sometimes return false?
This blog post might be worth reading to understand why js handles thing this way.
The value produced by a && or || operator is not necessarily of type Boolean. The value produced will always be the value of one of the two operand expressions.
Both && and || result in the value of (exactly) one of their operands:
- A && B returns the value A if A can be coerced into false; otherwise, it returns B.
- A || B returns the value A if A can be coerced into true; otherwise, it returns B.
If you want the result as a boolean, you can use "not-not", like this: !!expression
Related Topics
Reshape Data from Wide to Long
Convert Data with One Column and Multiple Rows into Multi Column Multi Row Data
How to Force the X-Axis Tick Marks to Appear at the End of Bar in Heatmap Graph
Changes in Plotting an Xts Object
How to Convert Class of Several Variables at Once
Stargazer Output Appears Below Text - Rmarkdown to PDF
How to Render Custom Map Tiles Created with Gdal2Tiles in Leaflet for R
Increasing Whitespace Between Legend Items in Ggplot2
How to Check If Multiple Strings Exist in Another String
R Bnlearn Eval Inside Function
Writing a Function to Calculate the Mean of Columns in a Dataframe in R
Reconstruct a Categorical Variable from Dummies in R
Map Array of Strings to an Array of Integers
R - Check If String Contains Dates Within Specific Date Range
Convert Byte Encoding to Unicode
How to Embed Plots into a Tab in Rmarkdown in a Procedural Fashion
Solve Homogenous System Ax = 0 for Any M * N Matrix a in R (Find Null Space Basis for A)