2 ms·
Values in JS still have different types (as evidenced by their different behavior). Variables could all be argued to have one type in JS, which is the root type
by int_19h 8y ago
Values in JS still have different types (as evidenced by their different behavior). Variables could all be argued to have one type in JS, which is the root type (which everything else subtypes).
So no, JS is still not untyped, merely dynamically typed. An example of a language that also has only one data type for value would be something like Tcl, where the only type is a string - and everything else is just an optimized way to store certain kinds of strings, that could be removed without affecting semantics of any program.
- kazinator 8y agoThey could be argued, but that would be wrong. If we define a variable, give it the value 42 and then never change it over the lifetime of the image, then that variable's type is integer. Or, even more specifically, its type is the set { 42 }. It may be the case that no such thing is actually analyzed and the implementation always retains the potential to reassign that variable; that doesn't change the mathematical fact that the set of values which that variable is fixed. That the implementation is not interested in examining the type of a variable (let alone checking for consistency with the rest of the program) shouldn't be mistaken for the absence of type. There is a mathematical fact about the program that isn't constrained by the quality and depth of its implementation.
- anon_d 8y agoJavascript is Unityped. In Haskell/ML, you would define the type of Javascript objects by doing something like this: data JSObj = Num Double | Str String | Obj (Hashtable String JSObj) | True | False | Nil | Undefined
- naasking 8y ago> Values in JS still have different types (as evidenced by their different behavior). Behaviour is based on values, not types. 1+2 will print out a different value than 1+1, but these expressions have the same type (typically). > So no, JS is still not untyped, merely dynamically typed. I said JS was unityped, not untyped.
- int_19h 8y agoValues also have types, it's not something that's exclusive to expressions and bindings.