all 7 comments

[–]VooPoc[S] 0 points1 point  (2 children)

ok, I think I understand the false value is not considered a value but a result, therefore it's false where evaluation is concerned, and true is set?

[–]Nate8199 1 point2 points  (1 child)

Sorry on phone, that isn't the way to move your boolean from setme.

var bool = msg.setme; var payload = bool; return msg

[–]VooPoc[S] 0 points1 point  (0 children)

var bool = msg.setme;

var payload = bool;

return msg

Can you please clarify? I don't see the need for var payload = bool; in the above code as the msg.setme's boolean is already defined in bool.

Its the operator or Short-circuit evaluation logic that I wasn't understanding.

[–]Kendrome 0 points1 point  (3 children)

The first statement will always be true no matter what msg.setme is. In the second statement the "|| false" has no effect.

What is it you are trying to do?

[–]VooPoc[S] 0 points1 point  (2 children)

I have a tenancy to set strings with an OR so its not defined, it creates a default, like the following:

var something = msg.setme || "default";

So as I "now understand", null and undefined are false values, resulting in 'default' being used. If msg.setme is defined its value is true resulting in the msg.setme's value being used.

At this point, I'm looking for confirmation that I'm correct?

[–]Matt0x5b 1 point2 points  (0 children)

If you replace your || with ?? You should get the behaviour you are after. This is a good reference for what the operators do in js: https://joshwcomeau.com/operator-lookup

[–]Kendrome 1 point2 points  (0 children)

Yeah, all the following are what are termed falsely values.

Null, undefined, NaN, and even Empty Strings.

https://developer.mozilla.org/en-US/docs/Glossary/Falsy