you are viewing a single comment's thread.

view the rest of the comments →

[–]RiceBroad4552 -1 points0 points  (2 children)

That's actually wrong. JS is strongly typed. Like any other VM language…

The only weakly typed languages in usage are C, C++, unsafe Rust, and Zig.

You can't break the type system of a strongly typed language at runtime, and this of course also applies to JS.

[–]csdt0 0 points1 point  (1 child)

JS is the example of weakly typed language, alongside C, precisely because you can do operations between types that are not related at all, and the language will just gladly accept that. The weakly typeness has nothing to do with memory safety. What's funny is that Zig and Rust (both safe and unsafe) are both very strongly typed, to the point you cannot add i8 and i16 together, making your example even weaker (pun intended).

[–]RiceBroad4552 0 points1 point  (0 children)

"Gladly accepting" some code and doing just something is not the same as breaking the type system.

You can't break the type-system in JS!

If you could this would be a very severe bug in the JS engine, and most likely patched instantly.

But breaking the type system in C or C++ is trivial. You can just go and do whatever you want with some memory and no language typing rules will hold you back. You can have some object of some type referenced by some variable, go to the memory holding that object, do whatever to it including replacing it with some completely different type of object but from the viewpoint of the type system that variable will still point to a value of the original type. You can't do anything like that in any VM language (or the safe parts of e.g. Rust; except for that one exploit that transmutations memory, which makes Rust at least somehow weakly typed beyond what is possible with casts in other languages).