JS之形参带默认值的写法代码
JS之形参带默认值的写法代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS之形参带默认值的写法代码</title>
</head>
<body>
<script>
function c(x, y){
//console.log(y); //结果:undefined或者值
if(y == undefined){
y = 3; //如果调用函数时,没有传递第二个参数y的值,那么让y=3
}
console.log(x + y); //结果:5 6
}
c(2);
c(2, 4);
</script>
</body>
</html>
Copyright [2018] by [羊驼可以吃吗] form [https://www.cnblogs.com/phpisfirst/]