Skip to content

Instantly share code, notes, and snippets.

@ywwwtseng
Last active January 27, 2019 03:59
Show Gist options
  • Save ywwwtseng/53159193588eb5d01f364eb8ec27c1df to your computer and use it in GitHub Desktop.
Save ywwwtseng/53159193588eb5d01f364eb8ec27c1df to your computer and use it in GitHub Desktop.
coercion

Coercion

Coercion 指 JS Engine 將資料從一個型別轉換成另一種型別。

  • Example 1: JS Engine 將 1 從 number 轉換成 string
var str = 1 + "2"; // "12"
  • Example 2: JS Engine 將 0, null, undefined, "" 轉換成 false
function say(words) {
	words = words || "default value";

	console.log(words);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment