window.console && console.log('hello')

if语句的另一种写法

  • 偶尔在代码中遇到window.console && console.log('hello'),那这代表什么?
  • 这其实是if语句的缩写。
    比如
window.console && console.log('hello');

相当于

if(window.console){
    console.log('hello');
}
想做一定有方法,不想做一定有理由。
原文地址:https://www.cnblogs.com/angle-xiu/p/13999563.html