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

JavaScript 程式執行原理:Event Loop

JavaScript 程式執行原理:Event Loop

[ Day 05 ] 用 Puppeteer 來做自動化機器人吧 (四) : Dockerize 篇

[ Day 05 ] 用 Puppeteer 來做自動化機器人吧 (四) : Dockerize 篇

[Release Notes] 20210317_v1 - Support Insert img path and save button in post editor

[Release Notes] 20210317_v1 - Support Insert img path and save button in post editor


Comments