Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 470 Bytes

notesToPlace.md

File metadata and controls

24 lines (17 loc) · 470 Bytes

Coercion

Is when we force one data type into another. This is because JS is pretty flexible handling data types.

Example:

console.log(1 + true);
console.log('1' + 1);

We force or coerce true into 1 and 1 int/number into 1 string

The following operators convert data types values into numbers: - * / % However, + as we saw, converts by default into a string.

console.log('1' + 1);
console.log('1' - 1);

Result: 11 0