JS implementation of four digital kilogram formatting methods to share
The so-called digital thousandth form, that is, from the single digit, add a comma between every three digits. For example, "10000". To meet this requirement, I initially wrote such a function:
Method 1
The code is as follows:
// Method 1
function toThousands(num) {
var result = [ ], counter = 0;
num = (num || 0).toString() ...
Posted by airo on Mon, 06 Dec 2021 20:19:46 -0800
5 - parameter default value, implied global variable, precompiled
(1) . function parameter default value
Initialization parameter. If it is not set, the default value of the parameter is undefined
function test(a, b){
console.log(a);
console.log(b);
}
test(1);
// 1
// undefined
Do not pass arguments, set default values for row parameters
Only es6 supports formal parameter assignment
function test(a ...
Posted by airwinx on Sat, 04 Dec 2021 20:12:29 -0800
Operators of js in ES6 (?.,?:,?,? =,)
1, Null merge operator (?)
The null value merge operator (?) is a logical operator. When the operand on the left is null or undefined, it returns the operand on the right. Otherwise, it returns the operand on the left. The null merge operator (?) is different from the logical or operator (|), which returns the right operand when the left opera ...
Posted by Dane on Fri, 03 Dec 2021 01:58:58 -0800
The direction of this in JS and changing the direction of this
1, this point
1. Definitions
this is a keyword used within the scope Global is rarely used, and most of it is used inside functions
2. Direction
2-1. Global usage
When used globally, this points to window
2-2. Function usage
Note: no matter how the function is defined, no matter where the function is, it only depends on the call of t ...
Posted by Russia on Fri, 03 Dec 2021 01:31:56 -0800
ES6 learning Chapter 5 regular extension
prefaceThis chapter introduces the extension of regular. Some knowledge that is not commonly used can be understood.Link to the original text of this chapter: Regular extensionRegExp constructorStarting from ES6, if the first parameter of RegExp constructor is a regular object and the second flag exists and is a flag parameter, TypeError will n ...
Posted by paulmo on Wed, 01 Dec 2021 07:04:10 -0800
Do you really know arrow functions
highlight: a11y-dark theme: channing-cyan
Arrow function
🙊 I believe everyone has used the arrow function. People who can use it have tried it repeatedly. They are afraid that if they use it wrong, they may choose not to use it. It is a matter of multiple codes and a few lines of words. But people who have used it say it's really cool. Then ...
Posted by madmindz on Tue, 30 Nov 2021 15:19:53 -0800
ES6 added API: String
This article introduces several new functions for unicode strings in ES6.String.prototype.codePointAtFunction type:(index?: number)=> number|undefinedcodePointAt is a prototype function that returns the code point value of the character in the string according to the passed in index parameter. This method can recognize 4-byte code points in ...
Posted by thetechgeek on Mon, 29 Nov 2021 04:43:24 -0800
ES6 learning Chapter 7 function extension
prefaceThis chapter introduces the extension of functions. Some knowledge that is not commonly used can be understood.Link to the original text of this chapter: Extension of function. Default values for function parametersES6 allows you to set default values for function parameters, that is, write them directly after the parameter definition.Wh ...
Posted by ace21 on Sun, 28 Nov 2021 19:13:09 -0800
Summary of JS interview questions
Previous points here: ↓ Summary of JS interview questions (I) Summary of JS interview questions (II) Summary of JS interview questions (III) Summary of JS interview questions (IV) Summary of JS interview questions (V) Summary of JS interview questions (6) Summary of JS interview questions (VII) 71. What is the compatibility between IE and ...
Posted by sadaf on Sat, 27 Nov 2021 23:55:37 -0800
Deconstruction assignment of objects in ES6
brief introduction
Deconstruction can be used not only for arrays, but also for objects.
let { foo, bar } = { foo: 'aaa', bar: 'bbb' };
foo // "aaa"
bar // "bbb"
There is an important difference between the deconstruction of objects and arrays. The elements of the array are arranged in order, and the value of the variable is determined b ...
Posted by dgny06 on Sat, 27 Nov 2021 10:39:43 -0800