When you switch from Java to JS and TypeScript is good to pay attention to this differences: [Post in continuous improvement …]

1. Equals are not equals

Coming from Java pay attention to the comparison operators in JavaScript. They behave differently from Java!

TypeScript requires explicit conversions and is much more similar to Java.

JavaScript Comment JS Typescript
== 5 == 5 : true
5 == ‘5’: true
’’== 0 : true
Automatic conversion of the type 5 == 5 : true
5 == ‘5’: compiler error
’’== 0 : compiler error
=== 5 === 5 : true
5 === ‘5’: false
’’ === 0: false
Type and value are compared 5 === 5 : true
5 === ‘5’: compiler error
’’ === 0: compiler error

 

2. Null is not undefined

In Java ‘null’ values are assigned to objects without value or undefined.

In JS and TS a variable without value is ‘undefined’ but not ‘null’. null is a value and can be assigned to a variable.

To add more complexity:

null == undefined :  true
null === undefined : false
null == null : true
null === null: true
undefined === undefined : true