Does “untyped” also mean “dynamically typed” in the academic CS world?

前端 未结 9 2077
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 17:17

I\'m reading a slide deck that states \"JavaScript is untyped.\" This contradicted what I thought to be true so I started digging to try and learn more.

Every answer

9条回答
  •  误落风尘
    2020-11-30 17:24

    Both statements are correct, depending on whether you are talking about values or variables. JavaScript variables are untyped, JavaScript values have types, and variables can range over any value type at runtime (i.e. 'dynamically').

    In JavaScript and many other languages, values and not variables carry types. All variables can range over all types of values and may be considered "dynamically typed" or "untyped" - from the perspective of type-checking a variable that has no/unknowable type and a variable that can take any type are logically and practically equivalent. When type theorists talk about languages and types, they are usually talking about this - variables carrying types - because they are interested in writing type checkers and compilers and so on, which operate on program text (i.e. variables) and not a running program in memory (i.e. values).

    By contrast in other languages, like C, variables carry types but values do not. In languages like Java, variables and values both carry types. In C++, some values (those with virtual functions) carry types and others do not. In some languages it is even possible for values to change types, although this is usually considered bad design.

提交回复
热议问题