Summary of uncommon operators and operators in js

Summary of uncommon operators and operators in js

Summary of common operators and operators in javascript

category

Operators

Arithmetic Operators +, –, *, /, % (modulo)
String Operators + string concatenation += string concatenation compound
Boolean Operators ! , &&, ||
Unary Operators ++ , -- , + (unary plus), - (unary minus)
Relational comparison operators < , <= , > , >= , != , == , === , !==
Bitwise Operators ~ Bitwise NOT & Bitwise AND | Bitwise OR ^ Bitwise XOR <<Left shift >>Signed right shift >>>Unsigned right shift
Assignment Operator = , compound assignments (+=, -=, *=, %=) compound bitwise assignments (~=, &=, |=, ^=, <<=, >>=, >>>=)
Object Operators .Property access, [] property or array access, new call constructor common object, delete variable property deletion, void (return undefined), in judgment property, instanceof prototype judgment
Other Operators ?: conditional operator, comma operator, () grouping operator, typeof type operator

Uncommon operators and operators in js

Nullish coalescing operator: ??

When the left operand is null or undefined, it returns the right operand, otherwise it returns the left operand.

null ?? 'huli' // huli
undefined ?? 'huli' // undefined
'' ?? 'huli' // ''
[] ?? 'huli' // []
({}) ?? 'huli' // {}
NaN ?? 'huli' // NaN
false ?? 'huli' // false
0 ?? 'huli' // 0

Logical null assignment: ??=

The logical null assignment operator (x ??= y) assigns a value to x only if it is nullish (null or undefined).

const a = { duration: 50 };

a.duration ??= 10;
console.log(a.duration);
// expected output: 50

a.speed ??= 25;
console.log(a.speed);
// expected output: 25

Logical OR: ||

If the existence is true, then it is true, , whichever is the previous

const a = 3;
const b = -2;
console.log(a > 0 || b > 0); // true

Can be a false value

null
undefined
NaN
"" and''
0
false

Logical or assignment: ||=

If yes, return; if no, assign value

const a = { duration: 50, title: '' };

a.duration ||= 10;
console.log(a.duration);
// expected output: 50

a.title ||= 'title is empty.';
console.log(a.title);
// expected output: "title is empty"

Logical AND: &&

If both exist, it is true, whichever is the latter.

const a = 3;
const b = -2;

console.log(a > 0 && b > 0);
// expected output: false

Logical AND assignment: &&=

Assign if exists

let a = 1;
let b = 0;

a &&= 2;
console.log(a);
// expected output: 2

b &&= 2;
console.log(b);
// expected output: 0

Optional chaining operator: ?.

The optional chaining operator ( ?. ) allows reading the value of a property that is deep in a chain of connected objects without having to explicitly verify that each reference in the chain is valid. The ?. operator functions similarly to the . chaining operator, except that instead of causing an error if the reference is nullish (null or undefined), the expression short-circuits to return undefined. When used with a function call, if the given function does not exist, undefined is returned.

const adventurer = {
  name: 'Alice',
  cat: {
    name: 'Dinah'
  }
};

const dogName = adventurer.dog?.name;
console.log(dogName);
// expected output: undefined

console.log(adventurer.someNonExistentMethod?.());
// expected output: undefined

Summarize

This is the end of this article about uncommon operators and operators in js. For more relevant js operators and operators, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • JavaScript operators explained in detail never before
  • Summary of uncommon js operation operators
  • JavaScript Basics Operators
  • Summary of some efficient magic operators in JS
  • Stop using absolute equality operators everywhere in JS
  • Let's take a look at the same old JS operator explanation

<<:  Implementation of effective user groups and initial user groups in Linux

>>:  Detailed tutorial on installing different (two) versions of MySQL database on Windows

Recommend

How to set Tomcat as an automatically started service? The quickest way

Set Tomcat to automatically start the service: I ...

MySql 8.0.11-Winxp64 (free installation version) configuration tutorial

1. Unzip the zip package to the installation dire...

vue-cli configuration uses Vuex's full process record

Table of contents Preface Installation and Usage ...

my.cnf (my.ini) important parameter optimization configuration instructions

MyISAM storage engine The MyISAM storage engine i...

Detailed steps to install MySQL on CentOS 7

In CentOS7, when we install MySQL, MariaDB will b...

A brief introduction to MySQL storage engine

1. MySql Architecture Before introducing the stor...

Summary of Linux command methods to view used commands

There are many commands used in the system, so ho...

Website User Experience Design (UE)

I just saw a post titled "Flow Theory and Des...

Detailed explanation of meta tags (the role of meta tags)

No matter how wonderful your personal website is,...

Detailed analysis of MySQL optimization of like and = performance

introduction Most people who have used databases ...

How to open external network access rights for mysql

As shown below: Mainly execute authorization comm...

Tutorial on installing MySQL 5.6 using RPM in CentOS

All previous projects were deployed in the Window...

Summary of several common logs in MySQL

Preface: In the MySQL system, there are many diff...

Hbase installation and configuration tutorial under Linux

Table of contents Hbase installation and configur...