JavaScript Red Book Notes

Source: Internet
Author: User

typeof detects the data type of a given variable and distinguishes functions and other objects by TypeOfvar message = ' Some string '; Console.log (typeof (Message));   "String" Console.log (typeof (null));  "Object" is a special return value because NULL is considered an empty object reference. Attention:
    • A variable that has not yet been declared can only do one thing, which is to use TypeOf to detect its data type
Undefined It is just a value, the value is Undefined. scenario: When declaring a variable with VAR, but without an assignment (without initialization), the variable returns undefined. The main purpose of undefined is to make a formal distinction between null object pointers and uninitialized variables, which I understand to distinguish whether the return value of a variable is null or undefinedWhen declaring a variable is not assigned a value, this variable is equivalent to undefined var message;console.log (message = = undefined); True no matter what the circumstances, do not put a variable value, set to undefined note:
    • For unassigned variables and undeclared variables, when the typeof is executed, the undefined is returned;
    • In the actual operation, only need to know a bit, when using typeof detection variables, if the return undefined, we will know that the variable is not assigned, or is not initialized;
NULL It has only one value, is the second data type with only one value, and its value is null. it represents an empty object pointer that returns "object" when detected using TypeOf.var message = Null;console.log (typeof (Message)); "Object" If you define a variable that will be used to hold the object in the future, it is better to initialize the variable to NULL because NULL is an empty object. If the variable does not have a true save object, the value of this variable should be null, not the other data type

JavaScript Red Book Notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.