This is my second article about getting started.

preface

At the end of last year, I bought the latest edition of JS Little Red Book. Taking advantage of this opportunity to participate in the gold digging activity to write an article, began to read while making some reading notes.

As a half of the code farmers, when reading the third edition of many places are confused, now look at this book, many knowledge points have become clear, so record the interesting knowledge points that did not notice before, as well as the new version of the new increase of some important knowledge points, while recording some interesting code execution results.

Chapter one and Two

The first and second chapters are mainly introductory. Including the history of JavaScript, function introduction, the use of

Chapter 3 (Language Basics)

This chapter is still some basics. It’s worth noting some new knowledge about ES6.

variable

  • letwithconstDeclaration is basically the same, block level scope, temporary dead zone, cannot be repeatedly declared the same variable name, must be declared before calling
  • constA variable must be initialized when it is declared and cannot be modified (object attributes can be modified, but references to them cannot be modified)
  • No longer in use in principlevarDeclare variables. Preferred to useconst, followed bylet

The data type

  • Using template literal syntax, toString() is called when an expression is converted to a string:
    let foo = {toString: () = > "World"};
    console.log(`Hello, ${ foo }! `) // Hello World!
    Copy the code

    The above template literal calls the object when it is converted to a stringfoothetoStringMethod, returns"World".

The operator

  • Increment/decrement operators

Whether the prefix increment or prefix decrement operators are used, the value of the variable changes before the statement is evaluated; Postfix increments and decrement occur after the statement is evaluated. The following code:

let num1 = 2;
let num2 = 20;
Copy the code
/ / the prefix version
let num3 = --num1 + num2;
let num4 = num1 + num2;
console.log(num3); / / 21
console.log(num4); / / 21
Copy the code
/ / the suffix
let num3 = num1-- + num2;
let num4 = num1 + num2;
console.log(num3); / / 22
console.log(num4); / / 21
Copy the code

The case for the suffix version may be a little harder to understand. As mentioned above, when num3 is calculated, num1 has not been decrement by the suffix version, so it is still 2 and num3 is 22. Then decrement num1 to 1 and num4 to 1 + 20 = 21.

  • The logic and operators are short-circuit operators, so the following code does not report an error:
let found = false;
let result = (found && abc); // ABC is the name of the undeclared variable
console.log(result); // false;
Copy the code

If the first operand determines the result, the second operand is never evaluated.

  • Logic or operators are also short-circuit operators and behave similarly

  • The index operator **

console.log(3支那2); / / 9
console.log(16支那0.5); / / 4
let num1 = 3;
num1 **= 2;
console.log(num1); / / 9
Copy the code
  • Any relational operator involved in comparisonNaN, are returnedfalse, the following interesting phenomena may occur:
let res1 = NaN < 3; //false
let res2 = NaN> =3; //false
Copy the code
  • The equal operator does the following:
true= =1; //true
true= =2; //false
Copy the code

It is recommended to use congruence === and incongruence at all times! = =.

statements

  • Tag statement, syntax:
// label: statement

start: for(let i = 0; i < count; i++){
    console.log(i);
}
Copy the code

A typical use of label statements is nested loops, referenced by a break or continue statement.

Afterword.

This article is mainly about the basic knowledge of JavaScript related to some knowledge points. I recorded some things I hadn’t noticed, and some interesting snippets of code that might not be useful. I was going to go on to chapter four, but I’m running out of time but chapter four is more important, and it’s worth a separate chapter. So much for this messy reading note.