In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you what is JavaScript programming, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Values, types, and operators
a. Value
1. In order to manipulate a large amount of bit data smoothly without causing data loss, we can divide these bits into blocks that represent different information. In JS, we call these blocks values.
2.6basic value types: number, string, boolean, object, function, and undefined types
b. Figures
1. The actual range of numbers that can be stored in JS is 1900 trillion, and the scientific and technological method with e (index) can be used, 2.998e8=2.99800000
two。 The precision is not high when using decimals.
There are three special values in 3.JS: Infinity,-Infinity and NaN, the first two for infinity and negative infinity, and NaN for "non-numeric"
c. Unary operator
1. Operators that use two values are called binary operators, while those that use one value are called unary operators. The minus operator can be used either as a unary operator or as a binary operator
d. Undefined value
1.null and undefined, used to represent meaningless values. They each express their own meaning and do not contain any information except for some.
e. Automatic type conversion
1. NaN is generated when some values cannot be explicitly converted to numbers, such as "five" or undefined. Please check to see if the wrong type conversion has occurred.
2. | | when the value on the left side can be converted to true, the value on the left side will be returned directly, otherwise the value on the right side will be returned. So this function of this symbol can be used to return the default value.
3. Value & when the value on the left can be converted to false, the & & operator returns the value on the left, not on the right.
4. Short circuit calculation: | | and & & the expression on the right is evaluated only if necessary.
Https://github.com/zhangyue0503/html5js/blob/master/eloquentjs/1.html
Program structure
a. Variable
1. Variables do not contain values, but refer to them: two different variables can refer to the same value.
b. Environment
We call the collection of variables and variable values at a given time the environment.
Https://github.com/zhangyue0503/html5js/blob/master/eloquentjs/2.html
Function
a. Lexical scope
Any external scope can access the variable that contains its arm scope. The visibility of variables within a function depends on the position of the function in the code. In a code block that contains a function definition, this function can access all variables in the code block, that is, variables in the code block above the function and variables within the function. This method of controlling variable visibility is called lexical scope (lexical scoping).
b. Call stack
Whenever a function is called, the current context information is stored at the top of the stack. When the function returns, the system deletes the context information stored at the top of the stack and uses it to continue executing the program
c. Closure
A function that wraps some local variables is a closure.
d. Recursion
In the standard JS implementation, the function execution efficiency of recursive writing is about 10 times slower than that of circular writing. Performing a simple loop operation is much more efficient than multiple function calls. If the concept of program processing is very complex, it is indeed a wise choice to sacrifice some efficiency in order to ensure that the program is simple and easy to understand. Unless the execution of the program is really too slow, don't focus on efficiency.
e. Function and its side effects
Compared with functions that directly produce side effects, functions that generate return values are easier to integrate into the new environment.
Https://github.com/zhangyue0503/html5js/blob/master/eloquentjs/3.html
Data structures: objects and arrays
The two most common ways to access properties in A.JS are using dots (.) and square brackets []. If you use a point, the part after the point must be a legal variable name, that is, write the attribute name directly. If you use square brackets, JS takes the return value of the expression in square brackets as the attribute name.
b. You can use the in operator to determine whether an object contains an attribute with a specific name
Https://github.com/zhangyue0503/html5js/blob/master/eloquentjs/4.html
Higher order function
a. Higher order function
1. If a function operates on other functions, that is, taking other functions as parameters or functions as return values, then we can call them higher-order functions.
B.map function
The Map method can call a function on each element in the array, and then use the return value to build a new array to transform the array.
Https://github.com/zhangyue0503/html5js/blob/master/eloquentjs/5.html
A deep understanding of the object
a. Method
When object.method () is called, a special variable this in the object points to the object to which the current method belongs
b. Prototype
1. When developers access properties that an object does not contain, they search for properties from the object prototype, followed by the prototype of the prototype, and so on. The prototype of the empty object is Object.prototype.
two。 Many objects provide their own default properties through special prototypes. Functions inherit from Function.prototype, arrays inherit from Array.prototype, and so on.
The result returned by the 3.Object.getPrototypeOf function is the object prototype. You can use a specific prototype to create objects using the Object.create method
c. Constructor function
1. In JS, using new before calling a function means calling its constructor
two。 The constructor contains the variable this that points to the new object, and unless the constructor explicitly returns the value of another object, the constructor returns the newly created object
3. An object created by the keyword new is called an instance of a constructor
4. The constructor is actually a function, so its actual prototype is Function.prototype, and the prototype property of the constructor is the prototype of the instance it creates, not the prototype of the constructor itself.
d. Override inherited properties
If there is an attribute with the same name in the prototype, when the property is called, the property in the prototype is no longer called, but the property we added to the object is called instead. But the prototype itself will not be modified.
e. Prototype pollution
1. You can define your own non-enumerable properties using the Object.defineProperty function, which allows us to control the property type when we create the property
two。 Use the object's hasOwnProperty method to determine whether it contains a property without searching for a prototype.
f. No prototype object
Can be created using Object.create (null)
g. Polymorphisms
H.Getter and Setter
i. Inherit
The instanceof operator traverses all inherited types
Https://github.com/zhangyue0503/html5js/blob/master/eloquentjs/6.html
Project practice: building an electronic ecosystem
Https://github.com/zhangyue0503/html5js/blob/master/eloquentjs/7.html
The above is what JavaScript programming is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.