Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created February 6, 2020 18:28
Show Gist options
  • Select an option

  • Save r3dm1ke/8b6f9453202ea60ca648fb09b492c8ec to your computer and use it in GitHub Desktop.

Select an option

Save r3dm1ke/8b6f9453202ea60ca648fb09b492c8ec to your computer and use it in GitHub Desktop.
Showing type coercion in JavaScript
/* Here, '5' will be converted to 5 */
5 == '5'; // true
5 === '5'; // false
/* Here, true will be converted to 1 */
1 == true; // true
1 > false; // true
0 === false; // false
// Here, JS will try to convert both of these to number
// Number('true') = NaN (Not a Number), but Number(true) = 1
'true' == true; // false
'true' === true; // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment