Release 0.3 Undefined Check for Removing Section Part

JavaScript has two “non-values”: undefined and null.

  • undefined means “no value”. Uninitialized variables are undefined:
        > var foo;
        > foo
        undefined
    

    If you read a non-existant property, you also get undefined:

        > var obj = {}; // empty object
        > obj.foo
        undefined
    

    Missing parameters are undefined, too:

        > function f(x) { return x }
        > f()
        undefined
    
  • null means “no object”. It is used as a non-value when an object is expected (parameters, last in a chain of objects, etc.).

Normally, you should treat undefined and null equivalently, as if they were the same non-value. One way of checking for them is via an explicit comparison:

    if (x === undefined || x === null) {
        ...
    }

Another way is to exploit the fact that both undefined and null are considered false:

    if (!x) {
        ...
    }

Warning: false0NaN and '' are also considered false.

In this code, I found that there is no “null” and “Undefined” judgment, I think this is extremely fatal because it will produce errors and crash the website.

From this revision of the code, I learned the importance of some basic logical thinking judgments, which is related to the “success” of the entire project in the future. It may be just a small neglect that could lead to the failure of the entire project.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s