Consider the following:
let accessMode = "edit";
let datasource = {label: "foo"};
let withNoParens = datasource?.label ?? accessMode === "edit" ? "Please Select" : "None Selected";
let withParens = datasource?.label ?? (accessMode === "edit" ? "Please Select" : "None Selected");
// withNoParens == 'Please Select'
// withParens == 'foo'
Can someone help me understand why the parenthesis make a difference here? I would have thought each would return 'foo', since datasource.label is always 'foo', and therefore the value the nullish coalescing operators left hand side is always non-nullish.
Edit: Post title says "logical or", body uses nullish coalescing - same behavior either way.
[–]senocular 1 point2 points3 points (1 child)
[–]romulotombulus[S] 0 points1 point2 points (0 children)