Three ways to determine whether an object is empty in js

  • 2020-03-30 01:03:07
  • OfStack

When writing js script, we often encounter the case that the object is empty or not an object. In this case, we can use if to judge it and then execute the corresponding processing methods. The specific methods to judge them are as follows:

1, if    (typeOf (x)     = =     "Undefined")

2, if    (typeOf (x)     ! =     "Object")

3, the if (! X)

The third one is the easiest, but the third one can't be determined by the mutually exclusive method of if (x), only before the object!

Java inside! When x is true, x must be false, but not here

Related articles: