[英]Console.log does not work inside Self Executing Anonymous functions
(function() {
console.log('Hello World');
})();
Does not print anything to console. 不打印任何内容到控制台。
(function() {
alert('Hello World');
})();
Gives an alert. 发出警报。 Why so ? 为什么这样 ?
Both alert and console are working, please check when you are using console.log in self executing function, you are calling that function by using these brackets () or not. 警报和控制台均正常工作,请检查是否在自执行函数中使用console.log时,是否使用这些方括号()调用该函数。 May be you are missing these in your code - 可能是您的代码中缺少这些-
**Incorrect Code -**
(function() {
console.log('Hello World');
});
**Correct Code -**
(function() {
console.log('Hello World');
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.