我见过一些在 console.log 中使用逗号的代码示例,我认为在组合字符串和变量时需要使用 + 运算符。你能解释一下其中的区别吗?
console.log("my list items", myListItems[0]);
alert("my list items" + myListItems[0]);
最佳答案
逗号分隔函数调用中的参数。
console.log
旨在接受多个参数。
alert
旨在只接受一个参数。
关于javascript - 为什么逗号在 console.log 中起作用而不是警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36865349/