# 函数默认值

在 ES6 之前,不能直接为函数的参数指定默认值,只能采取变通的方法。

<script>
	function log(x, y) {
		y = y || "world";
		console.log(x, y);
	}
	log("hello"); //hello world

	// es6 写法
	function log(x, y = "world") {
		console.log(x, y);
	}
	log("hello"); //hello  world
</script>
上次更新: 10/29/2019, 6:04:16 PM