[英]Can someone explain how this code even works?
I am reading this function and not at all understanding how this can work.我正在阅读此功能,但完全不了解它是如何工作的。
() => console.log(i) || Promise.resolve(i++ > 3)
Can a kind soul explain how a console.log can participate in a conditional?好心人能解释一下 console.log 如何参与条件吗?
I can even trans-pile this in typescript.我什至可以把它转成打字稿。
console.log(...)
returns undefined
, which is falsy; console.log(...)
返回undefined
,这是假的; so the expression after the or ||
所以后或表达
||
operator will always execute.运算符将始终执行。 This is just shorthand for:
这只是以下内容的简写:
() => {
console.log(i);
return Promise.resolve(i++ > 3);
}
console.log(...)
返回undefined
,其计算结果为假值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.