if true then function 的简写?

问题描述

让我直截了当地说。所以我在 Instagram 帖子上找到了类似这样的简写:

const bool = true
function myFunction (){
//smth
}
if(bool){
myFunction
}

我不记得它是什么,与 && 运算符的东西。有人吗?

抱歉有点跑题了,但我真的需要这个。

解决方法

也许您正在考虑使用 && 来短路

const bool = true;
const notBool = false;
function myFunction(){ console.log("hello,world!") };

bool && myFunction();
notBool && myFunction(); // nada!