Backbencher.dev

JS Daily 16 - Implicit Type Coercion

Last updated on 6 Dec, 2020

What is the output of following code?

console.log( 10 + "2");
----o----

Output is "102".

Plus operator + in JavaScript can be used for numeric addition or string concatenation. When one of the operands is of string type, + does concatenation. Therefore, in this example 10 is converted to a string and the output is "102".

--- ○ ---
Joby Joseph
Web Architect