``` _____ _ | ___| (_) | |____ ___ __ _ __ ___ ___ ___ _ ___ _ __ ___ | __\ \/ / '_ \| '__/ _ \/ __/ __| |/ _ \| '_ \/ __| | |___> <| |_) | | | __/\__ \__ \ | (_) | | | \__ \ \____/_/\_\ .__/|_| \___||___/___/_|\___/|_| |_|___/ | | |_| ___ ___ ____ ___ __ _____ ___ ___ __ / / \ | |_) | |_ | |_) / /\ | | / / \ | |_) ( (` \_\_/ |_| |_|__ |_| \ /_/--\ |_| \_\_/ |_| \ _)_) ``` <details><summary><b>Comma operator (,)</b></summary> ```javascript // Luôn lấy giá trị sau cùng let x = 1; (x++, x) // 2 (2, 3) // 3 ``` </details> <details><summary><b>in</b></summary> ```javascript const object1 = { prop: 'exists' }; "prop" in object1 // true ``` </details> <details><summary><b>Unary plus (+)</b></summary> ```javascript // string to number +'1' // 1 ``` </details> <details><summary><b>Non-null assertion operator !. </b></summary> ```html // Toán tử xác nhận không null <div *ngIf="hero"> The hero's name is {{hero!.name}} </div> ``` </details> <details><summary><b>Do not use ~~ to truncate numbers to integers</b></summary> ```javascript // Do not use ~~x to truncate numbers to integers ~~2.6 // 2 // use Math.trunc() instead Math.trunc(2.6) // 2 ``` </details> <details><summary><b>Addition assignment += Toán tử gán phép cộng</b></summary> ```javascript // x = x + 2; // x += 2 1 += 2 // 3; 1 += true // 2; 1 += false // 1; 1 += 'food' // '1food' // BigInt + BigInt 1n += 2n // 3n; ``` </details> <details><summary><b>Subtraction assignment -= Toán tử gán phép trừ</b></summary> ```javascript let a = 3; a = a - 2; // 1 a -= 2 // 1 ``` </details> <details><summary><b>Remainder assignment %= Toán tử gán phần dư</b></summary> ```javascript let a = 3; a %= 2; // 1 a %= 3 // 0 ``` </details> <details><summary><b>Nullish coalescing operator ?? Toán tử kết hợp nullish </b></summary> ```javascript // Same console.log(null ?? 'default string'); console.log(undefined ?? 'default string'); console.log(null || 'default string'); console.log(undefined || 'default string'); // "default string" // "default string" // "default string" // "default string" // Different console.log(0 ?? 'default string'); console.log(false ?? 'default string'); console.log(0 || 'default string'); console.log(false || 'default string'); // 0 // false // "default string" // "default string" ``` </details> <details><summary><b>Nullish coalescing assignment ??= Toán tử gán nullish kết hợp</b></summary> ```javascript - Được sử dụng để gán giá trị cho biến nếu biến đó là null. - Nếu biến không phải là null, giá trị của biến sẽ không bị thay đổi. const a = { duration: 50 }; a.speed ??= 25; // a.speed = 25 a.duration ??= 10 // a.duration = 50 ``` </details> <details><summary><b>Logical OR assignment ||= Toán tử gán logic OR chỉ gán nếu x là falsy</b></summary> ```javascript const a = { duration: 50, title: '' }; a.duration ||= 10; // 50 a.title ||= 'title is empty.'; // "title is empty." ``` </details> <details><summary><b>Logical AND assignment (&&=) Toán tử gán AND chỉ gán nếu xlà true</b></summary> ```javascript - Được sử dụng để kiểm tra một điều kiện và gán giá trị cho biến dựa trên kết quả của điều kiện đó. - Nếu điều kiện là true, giá trị gán sẽ được thực hiện. - Nếu điều kiện là false, giá trị gán sẽ không được thực hiện. let a = 1; let b = 0; a &&= 2; // 2 b &&= 2; // 0 ``` </details> <details><summary><b>Destructuring assignment</b></summary> ```javascript let a, b, rest; [a, b, ...rest] = [10, 20, 30, 40, 50]; // rest: [30, 40, 50] ``` </details> <details><summary><b>yield</b></summary> ```javascript function* foo(index) { yield index; yield index+1; yield index+2; // while (index < 4) { // yield index; // index++; // } } const iterator = foo(1); // Gọi vào hàm foo một lần duy nhất console.log(iterator.next().value); // Output: 1 chạy yield 1 console.log(iterator.next().value); // Output: 2 chạy yield 2 console.log(iterator.next().value); // Output: 3 chạy yield 3 ``` </details> <details><summary><b>yield*</b></summary> ```javascript function* func1() { yield 42; yield 43; } function* func2() { yield* func1(); // yield* handle lại yield } const iterator = func2(); console.log(iterator.next().value); // 42 console.log(iterator.next().value); // 43 ``` </details> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators