There are a lot of operators in this chapter, which is quite interesting. Although I don't use much, I should at least know how to be a computer background.
3.4.6 String type
The string in ECMAScript is immutable.
let lang = 'Java'
lang = lang + 'Script'
Here, a space large enough to hold 10 characters will be allocated first, then filled with'Java' and'Script', and finally the original string'Java' and string'Script' are destroyed.
Template string
toString() is called when the expression is converted to a string:
let foo = {
toString: () => 'World'};
console.log(`Hello,${
foo}!`); // Hello World
3.4.7 Symbol type (called symbol in the fourth edition)
needs to be initialized with Symbo() function, because it is a primitive data type, so:
let sym = Symbol();
console.log(typeof sym); //symbol
3.5 Operator
2. Unary addition and subtraction operators
Similar to this rule is roughly the same, here is converted to numeric Number
let s1 = '01' s1 = +s1 //值为数值1
let s2 = '1.1' s2 = +s2 // 值为数值1.1
let s3 = 'z' s3 = +s3 //值为NaN NaN也是数值型 typeOf NaN 为number
let s4 = false s4 = +s4 //值为数值0
let s5 = 1.1 s5 = +s5 //值为数值1.1 不变
let o = {
o = +o //值为数值-1 会先调用他们的valueOf或toString方法转换
valueOf(){
return -1
}
}
Bitwise operator
1, bitwise not
2, bitwise and
3, bitwise or
4, bitwise XOR
5, left shift
6, signed right shift
7, unsigned right shift
3.5.4 multiplicative operator
3.5.5 Division operator
3.5.6 Modulus Operator
Exponential Operator
console.log(Math.pow(3,2)) // 9 与3 ** 2一样
console.log(Math.pow(16,0.5)) // 4
let a = 3
a **= 2
console.log(a) //9
Addition operator When
encountering a boolean value, regardless of addition and subtraction, it will call Number to convert the value. The
interesting thing is the
console.log(-0 - 0) // -0
console.log(-0 + 0) // 0
subtraction operator
here. The interesting thing is here, it seems that null plus + or-will be considered as +0 and -0
console.log(-undefined) // NaN
console.log(-null) // -0
3.5.7 Relational operators
3.5.8 Equality operators
3.5.11 The comma operator is
ok. I’m here today. Although there are many cut pictures, I have tried all the codes. You have to do it. I feel that the progress of writing notes is slow, but it is quite interesting.