【发布时间】:2020-07-27 10:46:09
【问题描述】:
categoryId = categoryId === '' && location.pathname.match(regExp) ?location.pathname.match(regExp)[1] : categoryId
我知道这是一个三元运算符,但 categoryId === '' && location.pathname.match(regExp) 在这里做什么?特别是对'' && location.pathname.match(regExp) 毫无头绪
是布尔值吗?
【问题讨论】:
-
这能回答你的问题吗? Assignment with double ampersand "&&"
-
显式分组括号和更常规的间距可能会有所帮助:
categoryId = ((categoryId === '') && (location.pathname.match(regExp))) ? location.pathname.match(regExp)[1] : categoryId
标签: javascript