Revision 58a8ceb4-1de9-46b8-b822-c3da08230a95 - Stack Overflow
In _weakly typed_ languages such as JavaScript you can use the strict comparison operator (`===`) because the language allows comparison between variables which have different _types_.
For example, in JavaScript, you won't get a _compile error_ if you do this:
var x = 10;
var y = 'foo';
console.log(x == y)
And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.
For example
var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false
In _strongly typed_ languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.
For example:
int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String
So, basically, in Java, there is no need for checking for strictness using `===` (a *syntax error* is reported).
In the first place, the compiler will complain when you compare values of different types and [conversion][1] cannot be performed.
In the previous example of Java code, if you want to make a comparison between `x` and `y` you could use `equals`:
int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String
As a side note, notice that [`Object.equals`][2] cannot be called on primitive types.
Some useful readings are:
- [15.21. Equality Operators][3]
- https://stackoverflow.com/questions/2690544/what-is-the-difference-between-a-strongly-typed-language-and-a-statically-typed
[1]: https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.8
[2]: https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)
[3]: https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.21