JavaScript language has been evolving in good direction over the time, but there is still some drawbacks that do not allow write a "safe" code by default:
- "implicit" type coercion - this feature was added in "ancient" time mostly for designers and by impact of C language where some type could be evaluated in if statement
But nowadays almost all understands that this feature is harmful and makes code less safe due to unpredictable behavior during "implicit" type coercion ...
Of course there are precise rules that describes conversion, but this rules is not consistent each other, I mean that if you know one rule, then you could not guess how it works with another type, because another type have different rule for coercion ... it make harder to reason about the code ... (
Also this feature make harder to implement the Operator Overloading Propousal I mentioned it in https://github.com/tc39/proposal-operator-overloading/issues/33 - Fix type of null as
null
- Use only
null
value as "empty" type or "nothing" type, undefined should be internal language value that user cannot set or read, if property is not available then should be raised exception (This is similar to Python where if symbol absent then would be raised error and there is exist only one "empty" typeNone
) - All scripts is run as module such that
this
is undefined - All objects that was created with specific keyword should be shown in typeof operator:
class SomeClass {
}
console.log(`SomeClass is ${typeof SomeClass}`); // SomeClass is class
It is consistent, because if we introcude a new keyword, then programmer would expect it as type:
// Future ...
interface ISome {
}
console.log(`ISome is ${typeof ISome}`); // ISome is interface
My suggestion is to remove inconsistencies and harmful features from language (those was described above) with adding esnext
type
It would be possible to do in browser
:
<script type="es2021">
// ...
</script>
and in node
environment with:
...
"type": "es2021",
...
type="es2021" could be the same thing that Rust use with edition, if over time developers realized that some features are harmful than it could be safely removed without breaking backward compatibility
Fortunately there is not so many Language Core
issue nowadays from my opinion ;)
If all this changes will be fixed, then I think I would call JavaScript - SafeScript ;)
Also I want to mention that I want to discuss this here and all these suggestions was impacted by my work with other languages such as C++
, Python
, Java
, C#
, Rust
and so on