I discovered something unexpected. If you do a raw TRUE/FALSE test on an object or variable that contains an object, the test will return TRUE. For example, "if MyObject", "if {abc:123}", and "if []" will all test as TRUE. This can be useful if a function returns FALSE or an object. And yes, I know you can also do a "if IsObject(xxx)" test to get the same results.
My question: Is this documented anywhere? I've looked but I haven't found anything.
Raw TRUE/FALSE test on an object Topic is solved
Re: Raw TRUE/FALSE test on an object Topic is solved
https://autohotkey.com/docs/Objects.htm#Usage_Remarksjballi wrote: ↑12 Jan 2019, 23:27I discovered something unexpected. If you do a raw TRUE/FALSE test on an object or variable that contains an object, the test will return TRUE. For example, "if MyObject", "if {abc:123}", and "if []" will all test as TRUE. This can be useful if a function returns FALSE or an object. And yes, I know you can also do a "if IsObject(xxx)" test to get the same results.
My question: Is this documented anywhere? I've looked but I haven't found anything.
Re: Raw TRUE/FALSE test on an object
It is also implied by,
Cheers.expressions wrote:Boolean values: When an expression is required to evaluate to true or false (such as an IF-statement), a blank or zero result is considered false and all other results are considered true
Re: Raw TRUE/FALSE test on an object
Thanks guys! I guess I didn't look hard enough.
From the doc:
Objects are always considered true when a boolean value is required, such as in if obj, !obj or obj ? x : y.
From the doc:
Objects are always considered true when a boolean value is required, such as in if obj, !obj or obj ? x : y.