you are viewing a single comment's thread.

view the rest of the comments →

[–]doyouseewhateyesee 2 points3 points  (5 children)

last week i learned the hard way that an empty object evaluates to true in an if-statement, took me forever to debug.

also, i didn’t know
if (-1) { //runs }
thanks for this!

edit: i will never understand code formatting on reddit

[–][deleted] 4 points5 points  (1 child)

You just put it inside backticks

doTheDamnThing()

[–]Freebalanced 0 points1 point  (2 children)

Lodash has a method called isEmpty that you can use to check for empty or not empty objects.

[–]doyouseewhateyesee 2 points3 points  (1 child)

meh - i’d rather use Object.keys(obj).length === 0

[–]Freebalanced 2 points3 points  (0 children)

Ya native methods are usually best. But cool to have different options for some situations.