如題,今天做了一個探索,得出結果是:
均有打斷程序並返回對應值,如果不設置返回值則返回undefined。
設計程序如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="format-detection" content="telephone=no,email=no,adress=no">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>Title</title>
</head>
<body>
<script>
window.onload = ()=>{
const getReturn = ()=>{
console.log("這是程序return前的打印!");
return;
console.log("這是程序return后的打印!");
};
const getReturnFalse = ()=>{
console.log("這是程序return false前的打印!");
return false;
console.log("這是程序return false后的打印!");
};
const getReturn0 = ()=>{
console.log("這是程序return 0前的打印!");
return 0;
console.log("這是程序return 0后的打印!");
};
const getReturnabc = ()=>{
console.log("這是程序return abc前的打印!");
return "abc";
console.log("這是程序return abc后的打印!");
};
let returns = getReturn();
let returnFalse = getReturnFalse();
let return0 = getReturn0();
let returnabc = getReturnabc();
console.log("調用程序后的返回值:returns:"+returns+",returnFalse:"+returnFalse+",return0:"+return0+",returnabc:"+returnabc)
}
</script>
</body>
</html>
運行結果: