Array.prototype.includes
Includes is a useful method on an Array to quickly find if an Array contains an element, including NaN (so unlike indexOf).
(() = > {
let arr = [1.2.3.NaN];
if (arr.includes(2)) {
// Find if 2 exists in arR array
console.log("Found it!); //>> Found!
}
if(! arr.includes(2.3)) {
// The second parameter 3 represents the item with subscript 3 in the array, which is the fourth item to start the search
console.warn("It doesn't exist!); //>> Does not exist!
}
The following two sentences explain the difference between incluedes and indexOf
console.log(arr.includes(NaN)); //true
console.log(arr.indexOf(NaN) != -1); //false}) ();Copy the code
Infix notation for exponential functions
This is a feature related to math.pow, remember i++,x += x, and infix notation for exponential functions is similar. Like the Python language, JavaScript uses the two-star ** symbol for Math.pow. The benefits are twofold:
- A. Infix notation is more concise than functional notation, which makes it preferable.
- B. Convenient calculation in mathematics, physics, robotics and other fields.
X ** y = x ** y
let squared = 2支那2;// Is equivalent to: 2 * 2
let cubed = 2支那3;// Is equivalent to: 2 * 2 * 2
Copy the code
X **= y
let a = 2;
a **= 2;A = a * a;
let b = 3;
b **= 3;// a = b* b* b**; 支那
Copy the code
That’s right, it’s a very sweet syntax candy.