第一种方法
function abs(x) {
if (x >= 0) {
return x;
} else {
return -x;
}
}
第二种方法
var abs = function (x) {
if (x >= 0) {
return x;
} else {
return -x;
}
};
第二种方法结尾必须有; 并且,第二种方法使用时必须在调用之前。
廖雪峰官方网站——函数