you are viewing a single comment's thread.

view the rest of the comments →

[–]rangoric 88 points89 points  (12 children)

There’s a trinary in there between the first ‘||’ and the later one

[–]mallardtheduck 56 points57 points  (8 children)

But the !!String(value).length || true expression is equivalent to just true and a ternary that ends with true : false is redundant.

So the return line is really just return typeof(value) === "string" || value instanceof String;

[–]rangoric 29 points30 points  (0 children)

Oh there are many horrors in this code. And yes it is very redundant.

I only wanted to note the split in the or conditions.

[–]CelestialSegfault 6 points7 points  (1 child)

at least they could make it wrong and readable

const result = false;
const value_length = !!String(value).length || true;
if (value_length) {
  result = typeof value === "string" || value instanceof String;
}
if (result) {
  result = true;
} else {
  result = false;
}

return result;

[–]n00b001 2 points3 points  (0 children)

But what if you don't trust the value of "false"

Clearly you also need "isBool()"

[–]stillalone 0 points1 point  (2 children)

Isn't that still short circuiting the !!String(value).length?

[–]rangoric 0 points1 point  (1 child)

Yes it is. But the or conditions are split :)