The introduction

After the project finished now hand, began to prepare for the internship to find a job, before the level of her now some confusion, don’t know his present position, after the front-end brother talked with tencent, himself went to the interview several companies, including bytes to beat some of the lesser-known companies and chengdu, basically made clear their front level, I also made a front end review plan for myself. Later, we will continue to review according to this plan and prepare for spring recruitment.

An introduction to a,

JavaScript is a weakly typed dynamic language. Although there are no strict restrictions on variable types, JavaScript also has its own data types. JavaScript mainly contains six data types. They are String, Boolean, Number, undefined, NULL, and Object. The Object types include Array, Function, RegExp, and Date.

Two, six types

2.1.undefinedtype

Undefined is used to indicate that a variable is defined but not initialized. It has only one value, which is the special undefined. The difference between undefined and not defined is that the variable is defined and belongs to one of the six basic types. The latter means that the variable is not defined, but they have the same thing in that there is no way to do anything with either one. The typeof operator can be used to remove undefined.

2.2.NULLtype

The NULL type is the second data type that has only one value. The value is NULL. NULL is used to determine whether a value stores a reference to an object.

  • usetypeofThe operator tonullValue is returned when detectedobjectThat’s because, from a logical point of view,nullValue represents a null object pointer. This is the principle behind the main functions discussed above. When creating a variable to hold an object, it is recommended that the variable be initialized tonull, so only need to checknullValue checks whether the variable holds a reference to an object.
  • undefined == nullThe reason is that,undefinedIs derived fromnullThe value of.

2.3 Booleantype

Boolean has two values, including true and false. Literals of this type are case sensitive. Only all lowercase characters are Boolean values. Boolean types themselves contain a Boolean() method that converts values of other types to Boolean types. It should be noted that after this method is converted, different cases correspond to different values.

2.4Numbertype

The JavaScript Number type uses the IEEE754 format to represent integer and floating point values. Why introduce this format here? We’ll talk about floating point values later. That’s why it’s equal to 0.3. General is the default value of the type of Number of decimal said, of course, also can be directly said octal and hexadecimal, octal said to zero for the first place, hexadecimal representation for 0 x for the first place, but it is important to note that whether a few hexadecimal representation, when involved in the operation of all took the form of decimal arithmetic. There are also a few things to note in the Number type:

  • 1. Floating-point value A floating-point value is an exponent that must have a decimal point and the number of decimal places following it must not be 0. Otherwise, it will be interpreted as an integereTo do scientific notation, it’s important to note that floating-point numbers have a maximum accuracy of 17 bits, and any bits beyond that will be truncated, which is why0.1 + 0.2! = 0.3When the operation is performed, the value is first converted to binary, and when the operation is finished, it is converted back again, and the final value is0.3000000000004So it’s not equal.
  • 2. Value rangeNumberThe value range of the type is ±2^57^. Solutions for numbers beyond this range include using plug-ins, or splitting them into arrays.
  • 3.NaNThis value is used when an operand that was supposed to return a value does not return a value, to prevent throwing an error. There are two things to note here. 1.NaN ! = NaN.NaNNot equal to any value, including himself. 2.isNaN()This function checks whether an argument is a numeric value, attempts to convert it to a numeric value if it is not, and returns if it cannot be convertedfalseThe little Red Book notes that this function applies to objects, which are called first when the argument is an objectvalueof()Method, if it cannot be converted to a value, is called againtoString()Method to convert
  • Numerical conversions here refer to explicit conversions, which are performed in three main ways: 1.Number() 2.parseInt(), the first parameter is the number to convert, and the second parameter is base 3.parseFloat()Is converted to decimal only

2.5Stringtype

Strings are a very common type. Note that strings are immutable. If you want to change the value of a string, you need to destroy the original string and create a new one. The second is that when converted to a String, there are two methods, toString() and String(), which actually call the former.

2.6Objecttype

There is a sentence called JavaScript everything is an object, object is the basis of JavaScript, here but more description, later topic review, here only briefly mention this type has the attributes and methods: 1. The constructor, which in ES6 also has this property, is a syntactic sugar for the constructor. HasOwnPrototype (): checks whether the object instance (not the prototype) has an attribute. IsPrototypeOf (): checks whether the parameter is the prototype of the current object. PrototyIsEnumberable (): allows for-in enumeration 5.toLocalString() 6.toString() 7.valueOf()

Third, the type of judgment

3.1.typeof()

All the five basic types can be determined. For Object reference type, only function can be determined.

3.2.instanceof()

This is a method based on the prototype chain of objects. It will look up along the prototype chain to determine the specific type of an object. Constructor can also be used, but it is not stable because the original constructor is lost if the developer modifies the prototype during development.