JavaScript Implict Conversion to String

Implicit conversion is when JavaScript automatically converts one data type to another.

let str;

str = '1' + 2; 
console.log(str) // "12"

str = '1' + true; 
console.log(str); // "1true"

str = '1' + undefined; 
console.log(str); // "1undefined"

str = '1' + null; 
console.log(str); // "1null"

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Difference between Validations, Callbacks and Observers