Raw TRUE/FALSE test on an object Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jballi
Posts: 724
Joined: 29 Sep 2013, 17:34

Raw TRUE/FALSE test on an object

12 Jan 2019, 23:27

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.
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: Raw TRUE/FALSE test on an object  Topic is solved

13 Jan 2019, 00:30

jballi wrote:
12 Jan 2019, 23:27
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.
https://autohotkey.com/docs/Objects.htm#Usage_Remarks
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Raw TRUE/FALSE test on an object

13 Jan 2019, 00:34

It is also implied by,
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
Cheers.
User avatar
jballi
Posts: 724
Joined: 29 Sep 2013, 17:34

Re: Raw TRUE/FALSE test on an object

13 Jan 2019, 11:10

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 176 guests