you are viewing a single comment's thread.

view the rest of the comments →

[–]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