JavaScript in layman's language-learning notes

Source: Internet
Author: User
Tags arithmetic operators

In MU class before learning JS to understand, recently found a lot of things are not very clear, and then review again good, feel this course is really super good, do notes, and then add some learning content?? Always add

Course Outline
1. Data type
2. Expressions and operators
3. Statements
4. Objects
5. Arrays
6. Functions
7.this
8. Closures and scopes
9.OOP
10. Regular Expressions
Learning materials:
Jacascript Authoritative Guide
MDN Https://developer.mozilla.org/zh-CN/docs/learn/JavaScript Firefox's MBN
More hands-on practice + participation in discussions

First chapter data type:
1. Six types of data
Weak type characteristics
var num=32;
Num= "This is a string";

32+32//64
"32" +32//"3232"
"32"-32//0

Data type: Primitive Type "number,string,bollean,null,undefined" Object Type "Function Array Date ..."
2. Implicit conversions
+ -
var x= ' The answer is ' +42; string concatenation
var y=42+ ' is the Answerr '; string concatenation
"37"-7//30
"37" +7//377

Skillfully use +/-rule conversion type
num-0//Turn numbers
num+ '//Turn string

A==b judgment
"1.23" ==1.23//true first convert the string to a number before comparing
0==false//true
null==undefined//true
Nwe object () ==new object ()//false compare address address different
[1,2]==[1,2]//false compare address address different

JS type conversion Pit http://www.cnblogs.com/diligenceday/p/4393210.html
Null,undefined, "", 0,-0,nan converted to Boolean is false, the remainder ("", "0") is converted to = = "true;"
NULL, "", False, "", [] converted to a number = = = "0;
Undefined, "One", an array of non-numeric values: ["a"],function () {} converted to a number = = "NaN;
True, a value is an array of numbers: [1], is a string of numbers: "1", converted to a number = = "1
The Isfinite () function is used to check whether its arguments are infinite. Returns true if it is not infinite, or false if infinite
Where null and undefined do not have constructors, they will report type errors when they are converted to objects.
JS converts an object to its original value
JS if the object is converted to a string, the object's ToString () method is called, if the value returned by the ToString () method is an object, the object's valueof () method is called, and the return value of valueof () is converted to a string. If the value is not the original value will be an error;
The valueof () method is called when the object is converted to a number, and if the method returns a value other than the original value, the object's ToString () is called, the return value of ToString is converted to a number, and if the ToString () return value is not the original value, then an error is made;
If the object type is converted to the original type, simply unpack the object that needs to be converted into the constructor of the original type, for example:
Number ({valueof:function () {return 1111}})//===>1111
String ({tostring:function () {return 1111}})//===> "1111"
Boolean ({})//===>true
If you're in trouble, you can quickly convert by arithmetic operators:
var obj={tostring:function () {returnn 1111}};
obj+ "" ==>> "1111";
var obj={valueof:function () {return 1111}};
+obj==>>1111;
JS transforms the original value into an object
To convert the original type to an object type to put the original type into the constructor of the object type, you need to wrap the constructor;
Console.log (typeof ture); ==>>boolean
Console.log (typeof new Boolean (true))//== "Object

Primitive types and Object types

JavaScript in layman's language-learning 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.