How is the nullish coalescing operator (??) different from the logical OR operator (||) in ECMAScript?
问题 ES2020 introduced the nullish coalescing operator ( ?? ) which returns the right operand if the left operand is null or undefined. This functionality is similar to the logical OR operator ( || ) . For example, the below expressions return the same results. const a = undefined const b = "B" const orOperator = a || b const nullishOperator = a ?? b console.log({ orOperator, nullishOperator }) result: { orOperator:"B", nullishOperator:"B" } So how is the nullish operator different and what is its