tags: javascript es6
1.let and const replaced VAR
The LET declaration variable will not be hung in Window, and will not cause global pollution; let new add -level agglomeration scope; let is not allowed to repeat declarations; let does not have a statement improvement, but it is improved to a temporary dead area.
CONST is the same as Let, but Const defines constants, not allowed to be modified, not allowed to change the memory address, and the Const declaration and assignment must be completed at one time.
console.log(a);
var a = 10;
console.log(b);
let b = 10;
The above code A will output UNDEFINED, B will directly report an error.
In the global environment, the use of CONST, especially in the global environment, should not be set up variables, but only constants should be set. Const declares that there are two benefits. One is that people who read the code immediately realize that this value should not be modified, and the other is to prevent errors caused by inadvertently modifying the value value. All functions should be set to constant.
Static string uses single quotes or anti -quotes, and dynamic strings use anti -attract numbers.
// bad
const a = "foobar";
const b = 'foo' + a + 'bar';
// acceptable
const c = `foobar`;
// good
const a = 'foobar';
const b = `foo${a}bar`;
When using array members to assign variables, the deconstruction assignment is preferred.
const arr = [1, 2, 3, 4];
// bad
const first = arr[0];
const second = arr[1];
// good
const [first, second] = arr;
Use the extension operator (...) to copy and conversion to the array
The main role of the extended operator, expand the array, collect the array content
const arrCopy = [...arr];
let arr = [...document.querySelectorAll('div')]
console.log(arr)
Good book Master some basics of ES6 to read The book progresses from shallow to deep Code warehouse Some concepts and codes First-class citizen When a gate allows the function to be used as any other ...
Hey, hello everyone, let’s talk to you in this article today ES6 Implementation of asynchronous programming. of course,ES6 A variety of solutions are proposed in, let’s talk...
Java: ...
On gitbook a few days ago, I turned to Google’s [Java Code Programming Style Specification](https://legacy.gitbook.com/book/jervyshi/google-java-styleguide-zh/ details), I spent som...
Just like writing, writing code is also code style. However, the code style is different from the style of writing. A person's style of writing can be arbitrary, and the code style is best to be &qu...
simple rxjava code programming style in app's gradle,need ref:...
Also wrote quite a long time js code, go back to the basic question many have not noticed, again seriously study the code specifications, or necessary to learn, a good start is half the battle, even i...
Foreword No rules, no standards useletReplace var to define the variable. If it is a constant, useconst Static stringUniform useapostrophe'' , Dynamically stitched into a stringUniform useBack quote``...
717. 1-bit and 2-bit Characters We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). Now given a string ...
20. Sequence structure The most basic structure of Java is the sequential structure, unless otherwise specified, it is executed in order, sentence by sentence Sequence structure is the simplest algori...