什么是window.console&& CONSOLE.LOG? [英] What is window.console && console.log?
问题描述
if (open_date) {
open_date = get_date_from_string(open_date);
window.console && console.log(open_date);
window.console && console.log(cancel_until);
什么是 window.console&& console.log
?它必须在代码中吗?通过这个脚本不适用于IE(所有版本) - > IE运行javascript仅在按F12后
What is window.console && console.log
? Does it have to be in the code? Through this script does not work on IE (all version) --> IE runs javascript only after pressing F12
推荐答案
只有当leftside-expression为<$ c时,才会评估rightside-expression $ C> truthy 。这就是逻辑AND 运算符的工作原理。
The rightside-expression will only get evaluated if the leftside-expression is truthy
. Thats how the logical AND operator works.
它基本上是
if( window.console ) {
console.log( open_date );
}
正如你可能猜到的那样,这是一种常见的情况,因为 console
对象可能无法在每个浏览器(尤其是手机)上使用。
As you might guess correctly, it's a common pattern for this case, because the console
object might not be available on every browser (especially mobiles).
这篇关于什么是window.console&& CONSOLE.LOG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!