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.