JavaScript Learning Notes (ii) JS Some basic concepts _ basic knowledge

Source: Internet
Author: User
1.typeof operator: The data type used to detect a given variable
Copy Code code 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 string:
"Undefined", "Boolean", "string", "number", "Object", "function".

An instance of 2.Object has properties and methods:
constructor--saves the function used to create the current object.
hasOwnProperty ("Property name")--detects whether a given property is a property of the current object instance (not in the prototype of the instance).
isPrototypeOf (object name)--detects if an incoming object is a prototype of another object
ToString ()--Returns the string representation of an object
valueof ()--returns different original values based on different objects, and usually returns the same result as ToString

3. Operator
! Logical non
Operand is an object that returns false
The operand is an empty string that returns True
The operand is a non-empty string that returns false
Operand is a number 0, returns True
The operand is any character (including infinty) that is not 0, and returns false
The operand is null and returns True
Operand is NaN, returns true
Operand is undefined, returns true
* Multiplication
One 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 = =: congruent
Equality: first converts to the same type of value in the comparison
Congruent: Must be of the same type and equal in value

4. Type detection
Basic type with valueof
Copy Code code 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

Reference type with instanceof (return True or FALSE)
Copy Code code as follows:

Alert (person instanceof Object); is the variable person object?
Alert (colors instanceof arrary); Variable colors is array?
Alert (Parttern instanceof Regexp); Parttern is RegExp?
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.