3 ms·
Strong and weak are ill-defined, but JS is generally considered weakly typed. It's about how the language treats the results of expressions on mixed types and w
by Jtsummers 1y ago
Strong and weak are ill-defined, but JS is generally considered weakly typed. It's about how the language treats the results of expressions on mixed types and whether it permits implicit conversions or not. Contrast with Python, which is also dynamically typed but is strongly typed (by default, you could add in your own operations to weaken these runtime type checks).
JavaScript: https://tio.run/##bdBBCoMwEIXhfU4xuNFG01C6K3iYF2tLixhREXr6NJVuzMtumHwM4X9jw9LNr2k1o7/3IWyYBdJKcSnUb3ZxvirV@XHxQ38e/LNaP1PvH4JTbuuOW9SukfJWNvJ/ryB1RIkyrAwrzUqzsqzsrg7M1UiYix9DcswZVoaVZqVZWVZ2VypJhkwyUDJkkpHSyCQjZZFJFlUIXw https://tio.run/##bdBBCoMwEIXhfU4xuNFG01C6K3iYF2tLixhREXr6NJ...
Python: https://tio.run/##K6gsycjPM/7/P1HBVkHdUJ0rCUgbc3EVFGXmlWgkKmgrJGnCObrIHC1kjj6Q8/8/AA https://tio.run/##K6gsycjPM/7/P1HBVkHdUJ0rCUgbc3EVFGXmlWgkKm...
Few languages are truly strongly typed (zero implicit conversions, numeric operations commonly allow them without requiring explicit casts) so it's really more of a spectrum. How much does a language allow in comparison to other languages.
- RHSeeger 1y agoMost of the well thought out writeups on types that I've seen put them on two different scales - Strong vs Weak - how does the language convert between types - Static vs Dynamic - Does type information apply "early" or "late" (not sure what the right term here, but generally "when it's compiled" vs "when it's run"). I've also seen this as whether the type information is applied to the variable (name of/thing that points at the value) or the value itself; which tends to work out to the same thing. Which is, I think, more or less saying here. Just with more words.
- bhk 1y agoRe: conversion between types Most languages can be placed somewhere on a strong-weak spectrum, but JavaScript is an outlier. Two "equal" values can implicitly convert to opposite boolean values, or different numeric values, or different string values. Not just weak... maybe pathological is a better term.
- bloppe 1y agoIn static languages, variables have types. In dynamic languages, values have types.