if condition ! falsy value


Posted by mijouhsieh on 2023-03-27

// 錯誤寫法
if(!movies || !(movies.length === 0 )) { return }

正確寫法
if(!movies || !movies.length) return

movies.length若為0 就是 false
!false 就是 true
所以不用寫(movies.length === 0)

return 在同一行,不用寫{}


#|| #OR operator #! #debug







Related Posts

【SSH 技巧】使用 iTerm2 設定 Profile + Shell Script 自動登入 Server

【SSH 技巧】使用 iTerm2 設定 Profile + Shell Script 自動登入 Server

網站部屬

網站部屬

Vite系列#使用 Create Vue 版本進行創建

Vite系列#使用 Create Vue 版本進行創建


Comments