[JavaScript] ES5 Basic Knowledge Summary

Source: Internet
Author: User
Tags arithmetic array length

1.JavaScript is a dynamic language, the appearance of ES6 make up for JS in large projects on the weakness (with "class").

Here is a basic knowledge of ES5:

2.

Unlike traditional object-oriented languages such as C + + or Java, JavaScript actually presses
Gener no class. Everything in the language is object-based and relies on a prototype (prototype) system. and
The prototype itself is actually an object.

3.

Encapsulation: The concept of encapsulation is usually made up of two parts:
(1) Related data (for storing properties)
(2) What you can do based on this data (the method that can be called)

4.

In JavaScript, there is also a special value called infinity. It represents a place beyond the JavaScript
Value of the range. In addition, any number divided by 0 results is also infinity.
Even if we add the plus or minus infinity, we won't get 0, but we'll get an abbreviation called Nan (not a number).
of things.

5.

NaN: Although the worthy name is called ' Not a number ', it is actually a numeric type, but it is a special number.
If we use an inappropriate operand in an arithmetic operation that causes the operation to fail, the operation returns
NaN.
> var a = ten * "F";
> A;
NaN
And Nan is contagious, so long as there is a nan in our arithmetic operation, the whole operation will fail.
> 1 + 2 + NaN;
NaN

6. When we use a numeric string for an operand in an arithmetic operation, the string is used as a numeric type in the operation.

7.

Twice!! Value Restore
With double-fetching, we can easily convert any value to the corresponding Boolean value. Understand the various classes
It is important to convert the value of the type to the corresponding Boolean value. In addition to the specific values listed below (they will be converted
is false), most of the remaining values are true when converted to a Boolean value.
? Empty string "".
? Null.
? Undefined
? Number 0.
? The number Nan.
? A Boolean value of false.
These 6 values are sometimes referred to as falsy values, while others are called truthy values (including the string "0",
"", "false", and so on).

8. Comparison operators
the = = operator in JS is a bit less strict, divided into equality operators and strict equality operators:
Returns True when the two operands are equal. Before the comparison operation executes, the operands on both sides are automatically converted to the same type.
= = =: strict equality operator:
True if and only if the value and type of the two operands are all the same. This comparison is often more reliable because there is no form of type conversion behind the scenes.
! =: not an equality operator. (type will be converted)
!==: Strictly unequal operator. (type does not convert)
Ps:nan is not equal to anything, including its own.

9.Undefined, when using a non-existent variable, the console will error. However, you can use the TypeOf modifier to modify it. Returns a string of "undefined".
If we do not assign a value when declaring a variable, the variable is called without error, but the typeof operator still returns "undefined". But a null value is entirely another matter. It cannot be automatically assigned by JavaScript and can only be done by our code.
This is because the method has a certain difference when null and undefined are converted to other primitive types.
When operating with numbers, the undefined is converted to Nan.

10. Five major basic types (Number,boolean,string,undefined,null)
Ps:
(1) Anything that is not of the basic type belongs to the object,
(2) data types that can be stored include: positive and negative integers, floating-point numbers, hexadecimal numbers and octal numbers, exponents, and special values Nan, Infinity,-infinity.
(3) A string type stores all characters between a pair of quotation marks.
(4) The value of the null type is only one: null.
(5) The value of the undefined type is only one: undefined.
(6) Most of the values are true when converted to a Boolean type, except for the following 6 Falsy values: ""; null;undefined; 0; Nan;false.

11. Check the existence of variables, preferably using typeof to determine:
var result = "";
> if (typeof somevar!== "undefined") {
result = ' yes ';
}

12. For the array in JS, it can hold any type, can apply delete to remove an item, but after removing the array length will not be reduced, but the value of this item is undefined.
Add element: We can update the elements in the array by index.

Delete element: In order to delete a specific element, we need to use the delete operator. However, the length of the original array is not affected when the related element is deleted. In a sense, the location where the element was deleted was simply left blank.

[JavaScript] ES5 Basic Knowledge Summary

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.