Search code examples
javascripttype-coercion

If I use two negation operators on a string am I using type coercion?


Consider the following code:

!!('foo');

The negation operator uses the abstract operation ToBoolean to perform a type conversion, but my question is - does this involve type coercion?


Solution

  • According to wikipedia http://en.wikipedia.org/wiki/Type_conversion " the word coercion is used to denote an implicit conversion", so yes there is type coercion involved, since the conversion is enforced.

    Alo take a look at the answer to this question What is the difference between casting and coercing?