function func(a, b, c) { a = a === undefined ? 3 : a; //默认 3 b = b === undefined ? 3 : b; //默认 3 c = c === undefined ? 3 : c; //默认 3 return a + b + c;}alert(func(6, 6, 6)); //18alert(func()); //9alert(func(4)); //10alert(func(4, 0)); //7
JavaScript 演练(2). 默认参数
TAG: