Javascript learning notes (2) some basic concepts of js

Source: Internet
Author: User

1. typeof OPERATOR: used to detect the Data Type of a given variable
Copy codeThe Code is as follows:
Var message = "some string ";
Alert (typeof message); // "string"
Alert (typeof (message); // "string"
Alert (typeof 100); // "number"

The typeof operator may return the following strings:
"Undefined", "boolean", "string", "number", "object", "function ".

2. attributes and methods of the Object instance:
Constructor -- save the function used to create the current object.
HasOwnProperty ("property name") -- checks whether a given property is the property of the current object instance (instead of in the instance prototype ).
IsPrototypeOf (Object Name) -- checks whether the input object is a prototype of another object.
ToString () -- returns the string representation of the object
Valueof () -- return different original values based on different objects. It is usually the same as the return result of toString.

3. Operators
! Non-logical
Returns false if the operand is an object.
Returns true if the operand is an empty string.
Returns false if the operand is a non-null string.
Returns true if the operand is 0.
The operand is a non-zero arbitrary character (including Infinty), and false is returned.
Returns true if the operand is null.
Returns true if the operand is NaN.
Returns true if the operand is undefined.
* Multiplication
An operand is NaN and the result is NaN.
Infinity * 0 = NaN
Infinity * Non-0 = Infinity or-Infinity
Infinity * Infinity = Infinity
/Division
0/0 = NaN
Non-0/0 = Infinity or-Infinity
==: Equal
Equal: first convert to a value of the same type for comparison
Full: It must be of the same type and have the same value.

4. Type Detection
ValueOf for Basic Types
Copy codeThe Code is as follows:
Var s = "ILoveYou ";
Var B = true;
Var I = 10;
Var u;
Var n = null;
Var o = new Object ();
Alert (typeof s); // string
Alert (typeof I); // number
Alert (typeof B); // boolean
Alert (typeof u); // undefined
Alert (typeof n); // object
Alert (typeof o); // object

Instanceof for reference type (return true or false)
Copy codeThe Code is as follows:
Alert (person instanceof Object); // is the variable "person" an Object?
Alert (colors instanceof Arrary); // is the variable colors Array?
Alert (parttern instanceof Regexp); // is parttern Regexp?

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.