I learned that JavaScript is a "loosely-typed" language.
What other languages are "loosely-typed?"
I learned that JavaScript is a "loosely-typed" language.
What other languages are "loosely-typed?"
There is disagreement about exactly what "loose" or "weak typing means, however, in so far as commonly understood, "loose typing" refers to a language that has more forgiving typing rules, and might even implicitly convert types from one type to another.
From Wikipedia:
Liskov and Zilles defined a strongly-typed language as one in which "whenever an object is passed from a calling function to a called function, its type must be compatible with the type declared in the called function."
According to this definition, JavaScript is loosely-typed (ie. the opposite of strongly typed) because most of JavaScript operators will coerce their operands if necessary.
For example:
[2]-1 // 1 (equivalent to 2-1)
[2]+1 // 21 (equivalent to String([2]) + '1')
true && {} // No error, returns `{}`
Another example of a loosely-typed language example is C.
Note that JavaScript is also dynamically typed. This means that the type of a value is bound to the value and checked at runtime, instead of being bound to the variable and checked at compile time. In effect type checking is performed "dynamically" (ie at runtime) as opposed to "statically" (ie. at compile time).
Examples of dynamic languages:
many of the interpreted languages such as php or pearl, in short a loosely-typed language is a language that does not require a variable to be defined