2016-08-18 92 views
-3

我發現這個地方:而不是if (count != undefined && count != null),使用if(count != null)。可以交替使用if (count == null)if(!count)嗎?(count!= null)vs if(!count)in javascript

+1

'count!= undefined && count!= null'與* count!= null完全相同。如果'count'爲'null','undefined','0','NaN',空字符串或'false',則'count'爲true。 (當我尋找重複時轉換爲答案) – Ryan

+0

https://dorey.github.io/JavaScript-Equality-Table/ – Nit

回答

5

count != undefined && count != null恰好是count != null相同。 !count如果countnull,undefined,0,NaN,空字符串或false爲真。