> 3 == "3"
true
> 3 * "3"
9=== does no type coercion. You can also coerce types manually. JS is not statically typed, but it is typed.
> A language is typed if the specification of _every_ operation defines types of data to which the operation is applicable, with the implication that it is not applicable to other types.
For a language to be typed, both the data must have a type and the operations must have a type specification.
> "a" * "b"
NaN
In a dynamically typed language, that specification is enforced at runtime. > true / false
Infinity
In a statically typed language, that specification is enforced by a compiler. > setInterval(function(){ console.log("hi") }, "later")
> hi
> hi
> hi
> hi
...
As far as I can tell, JavaScript doesn't concern itself with any of that. It's not typed.Javascript's type coercion leads to some wacky things like
> [] == []
> false
But it's actually all perfectly consistent once you understand what the compiler is doing with type (and JavaScript is compiled, not interpreted). == is an operator that will always try to coerce its operands to numbers, but the way it gets there can be circuitous.
You can specify type in JavaScript and avoid implicit coercion, you can use type constructors (generally worse) or certain unary operators. Ex:
> var foo = "12"
> var bar = +foo - 5; //+ explicitly converts foo to a number
Javascript is typed, it just makes a lot of crazy decisions about what operations an operator does.