What is Coercion in JavaScript?

 

In JavaScript conversion between different two build-in types called coercion.
Coercion comes in two forms in JavaScript: explicit and implicit.

 

Example of explicit coercion:

var a = "20";

var b = Number( a );

a;				// "20"
b;

What is Coercion in JavaScript? (Cont...)

 

Example of implicit coercion:

var a = "20";

var b = a * 1;	// "20" implicitly coerced to 20 here

a; // "20"
b; // 20 - the number

What is Coercion in JavaScript?

By Code 100mph

What is Coercion in JavaScript?

  • 152