弱类型:一种编程语言特性,指语言在运行时对数据类型的限制较弱,常会自动进行隐式类型转换(coercion),让不同类型的数据在同一运算中“凑合”工作;优点是灵活,缺点是更容易出现意料之外的结果。(注:不同语言/社区对“weak typing”的使用有时与“动态类型”混用,但严格来说两者并不等同。)
/wiːk ˈtaɪpɪŋ/
JavaScript is often cited as a language with weak typing.
JavaScript 常被认为是一种弱类型语言。
Because of weak typing and implicit coercion, the same expression may behave differently depending on the inputs, so careful validation is important.
由于弱类型和隐式类型转换,同一个表达式可能会因输入不同而表现不同,因此进行严格校验很重要。
weak 源自古英语 wāc,有“软弱的、不强的”之意;typing 来自 type(类型)+ -ing(名词化后缀),表示“类型系统/类型约束的方式”。合起来 weak typing 字面即“较弱的类型约束”,强调类型规则不严格、容易发生自动转换。