3 ms·
I don't think the presence of these facilities grants a type system a "strong" classification. None of them actually enforce anything on their own — they're jus
by DonaldPShimoda 7y ago
I don't think the presence of these facilities grants a type system a "strong" classification. None of them actually enforce anything on their own — they're just functions and expressions that are provided to the programmer to implement their own dynamic type-checking via introspection/reflection. They do not, on their own, constitute a strong type system.
Python is strongly typed because you cannot use a value of type X in a position where a value of type Y is expected. But Python doesn't check in advance — it just tries to go and do the thing. The trick to this is that Python's type system is actually structural instead of nominal; it doesn't care what the name of anything is, so long as it's got the right fields. (This is where we get "duck typing" from.) But you can't, for example, have Python do `"3" + 2`. A runtime error will result, because the language does not perform any implicit coercions.
JS is different. There are some native implicit coercions from certain types to other types. The presence of these makes JS's type system weaker than Python's, so in general I see it grouped as "weakly typed".
- michaelsbradley 7y agoYou can try the following in a browser's JS console or in a NodeJS REPL: > for (const x of [1,2,3]) { console.log(x); } 1 2 3 undefined > for (const x of {a:1,b:2,c:3}) { console.log(x); } TypeError: {(intermediate value)(intermediate value (intermediate value)} is not iterable So, sometimes JS automatically performs type conversions. But it also has the same kind of type-related runtime errors as Python. It just depends what you're doing.