That way if you ever need to add extra checks(like for comas, holidays, etc) you only need to change one place, and they can be inlined very easy by compilers.
If you're in a situation where a == comparison makes sense in JS/TS, you should change the situation and then change your comparison to ===. The eslint rules in my team forbid ==.
There is an inherent difference between the two operators. A software engineer could make use of that in a hypothetical situation.
The == operator was added to, and is still part of, the JS specification for some specific reason. That means at one point somebody was in need of that functionality and found it worth enough to add it.
Your team forbidding the == operator does not forbid somebody else making use of the quirks of said operator.
There is an inherent difference between the two operators.
I know about implicit type coercion, thank you.
A software engineer could make use of that in a hypothetical situation.
They shouldn't. Most engineers would agree that type coercion in JS, certainly on the backend, is something to avoid. the rules behind it are tricky and not always transparent enough. It makes code harder to read and certainly harder to understand. It's easy to make mistakes with, especially truthy/falsy errors.
The == operator was added to, and is still part of, the JS specification for some specific reason. That means at one point somebody was in need of that functionality and found it worth enough to add it.
While I can't comment with authority on why it exists as a language feature or why it's still there, it seems to me that it was added to make JS easier or maybe more approachable. A sort of "don't worry about types, JS will take care of that for you" type of thing. I think it's still there for backward compatibility. Just because it's there, that doesn't mean it's a good feature.
Your team forbidding the == operator does not forbid somebody else making use of the quirks of said operator.
I understand what you are trying to say but the statement is seriously flawed. The way you wrote it tells me that, for example, I shouldn't use pointers in C which is a core language feature.
69
u/Maoschanz Apr 09 '23
the secret of immortality
49
u/[deleted] Apr 09 '23
everyone knows comparison equals in JS would be
if (person ===================== !dead)
24
u/UtegRepublic Apr 09 '23
I don't know JS, but in C I'd write this as:
1
u/joao-simoes Apr 10 '23
Close enough!
1
u/balofg Apr 11 '23
This is neither cool, original nor correct.
EDIT: ah I didn't read what subreddit we're in
1
u/[deleted] Apr 12 '23
What no for Each with filter?
0
u/Ecstatic_Student8854 Apr 09 '23
Its a tapestry tbh
0
u/[deleted] Apr 10 '23
[deleted] — view deleted comment