<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function a() {
console.log(10);
}
console.log(a());
</script>
</body>
</html>
为什么输出的是
10
undefined### 题目描述
题目来源及自己的思路
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function a() {
console.log(10);
}
console.log(a());
</script>
</body>
</html>
为什么输出的是
10
undefined### 题目描述
// 请把代码文本粘贴到下方(请勿用图片代替代码)
10 回答11.2k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
你这个console.log(a())里面调用了a函数了,其实你输出的是a函数的返回值,因为你没有显式的声明return的返回值,所以默认情况下return undefined。要输出a函数你需要console.log(a)