扫码关注官方订阅号
alert(console.log('first time'))
为什么alert会弹出undefined?不应该弹出整个()里面的内容么?
alert
undefined
认证高级PHP讲师
你想多了,console.log是个方法,而这个方法的返回值恰好是undefined或者说“没有返回值”。 alert弹出的是console的返回值,也就是undefined了
console.log
console
console.log('first..') 返回的就是 undefined 楼主是想说alert('console.log("first time")')
console.log('first..')
alert('console.log("first time")')
alert会返回括号里的结果.
括号里的是console.log('first time')
console.log('first time')会向控制台打印'first time', 同时返回undefined.
你在浏览器 控制界面输入 console.log("first time") 会返回undefined
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
你想多了,
console.log是个方法,而这个方法的返回值恰好是undefined或者说“没有返回值”。alert弹出的是console的返回值,也就是undefined了console.log('first..')返回的就是undefined楼主是想说alert('console.log("first time")')alert会返回括号里的结果.
括号里的是console.log('first time')
console.log('first time')会向控制台打印'first time', 同时返回undefined.
你在浏览器 控制界面输入 console.log("first time") 会返回undefined