Appropriate is subjective, but it would involve needing to compare to identical values that are different types.
For example, let’s say we have two variables: X = 3 and Y = “3”
X == Y will return as true, but X === Y would return as false, because Y is technically a string type and X is a number type.
Now, I find it pretty trivial to set the two variables to the same type before doing a comparison, but that may not be the case for everyone. I could use ‘parseInt’ for example Which would turn Y from a string type to a number type.
Never say never, there’s probably some context out there where it still makes sense. It would be safe to take the position of defaulting to === and if you encounter an exception, then you make that decision.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Appropriate is subjective, but it would involve needing to compare to identical values that are different types.
For example, let’s say we have two variables: X = 3 and Y = “3”
X == Y will return as true, but X === Y would return as false, because Y is technically a string type and X is a number type.
Now, I find it pretty trivial to set the two variables to the same type before doing a comparison, but that may not be the case for everyone. I could use ‘parseInt’ for example Which would turn Y from a string type to a number type.
That's all evidence why you should use
===.Would you say that there is no reason to use
==?Never say never, there’s probably some context out there where it still makes sense. It would be safe to take the position of defaulting to === and if you encounter an exception, then you make that decision.