Netease front-end micro-major, JavaScript programming basics: basic syntax, basic type

Source: Internet
Author: User

Netease front-end micro-major, JavaScript programming basics: basic syntax, basic type

Ignore the basic syntax section. The basic types are as follows:

1. JS contains six data types: Number, String, Boolean, Object, Null, and Undefined. They are classified into the original type and reference type by type. Object is the reference type, and the other five types are the original types.

 

2. Let's talk about Number, integer, and floating point. values starting with 0 are octal, and those starting with 0x are hexadecimal. See the figure below:

 

Floating Point: Scientific Notation: var num = 3.12e2 indicates 312

Var num = 3.21e-1 indicates 0.321

In addition, there are two special NaN: not an Number and Infinity in number, for example, 1/0 indicates Infinity.

3. Double quotation marks of the String type are acceptable. Boolean Type ignored

4. Object Type: a unordered set of name-value pairs. Example:

 

Var dog = new Object (); dog. age = 100; dog. name = "a yellow"; dog. wang = function () {console. log ("" + dog. name + "in trademanager")}; dog. wang (); var cat = {name: "cat", age: 2, mew: function () {console. log ("") ;}}; cat. mew ();

Both methods can be used.

 

A method is used with function, and other variables are attributes.

 

5. Null type: there is only one scenario: var a = null;

 

6. Two Undefined scenarios are available: declared unassigned variables to obtain attributes that do not exist in the object. Test code:

 

var abc;console.log(typeof abc);var person = {a:1, b:2};console.log(typeof person.c);

7. Differences between the original type and the reference type

 

 

// Original Type example var a = 1; var B = 2; B = 4; console. log ("a =" + a); // reference type example var a = {a: 1}; var B = a; B. a = 100; console. log ("a =" +. a );
That is, the reference type stores the pointer, And the pointer is the object address.

 

 

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.