일종의 위장??보자마자 머릿속은??그렇게 되지 않기 위해서.
8263 단어 JavaScriptECMAScripttech
엔리스 Coalescing Opertor
구문
leftExpr ?? rightExpr
사용법
const y = null;
const z = 2;
const x = y ?? z;
console.log(x); // 2
const y = 6;
const z = null;
const x = y ?? z;
console.log(x); // 6
const y = undefined;
const z = null;
const x = y ?? z;
console.log(x); // null
const y = null;
const z = undefined;
const x = y ?? z;
console.log(x); // undefined
MDN에 따라정보
leftExpr ?? rightExpr
왼쪽이 비어 있거나 비어 있으면 오른쪽의 값을 되돌려줍니다. 그렇지 않으면 왼쪽의 값을 되돌려줍니다.이렇게 쓰여 있다.코드sandbox로 실험을 해보면??null이나 undefined가 아닌 것을 z로 되돌려 주는 것 같습니다.
(실제로는 y의 값을 평가해야 한다. 만약에 y가null 또는 y가undefined라면 z와 같은 글씨를 되돌려준다.😅)
우선순위는 y의 값을 평가하는 →y가null 또는 y가undefinded라면 z의 값을 평가하는 순서다.
??=연산자 정보
이것은 일종이다및 대입된 "="조합 연산자.
구문
expr1 ??= expr2
사용법
let y = 3;
const z = 5;
y ??= z;
console.log(y); // 3
let y = null;
const z = 5;
y ??= z;
console.log(y); // 5
??=는 다음과 같습니다.x ?? (x = y);
즉, x가null이 아니거나 x가undefined가 아니라면 y의 값을 x에 대입한다.자주 대입하는 아래의 부등가
x = x ?? y;
Optional Chaning(정보...)
사용법
const object = {
property: {
property: {
property: "value"
}
}
}
if (object?.property?.property?.property) {
object.property.property.property = "new value";
}
"?."비어 있거나 비어 있을 때의undefined를 되돌려줍니다.내포된 객체의 값을 확인하는 데 도움이 됩니다.
기타
다른 사람의 재난?의 구문에 세 개의 연산자가 있습니다.
이 보도에서python에 대해 js를 비교하고 세 가지 연산자의 쓰기를 조사했다.
참고 자료
Reference
이 문제에 관하여(일종의 위장??보자마자 머릿속은??그렇게 되지 않기 위해서.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/mo_ri_regen/articles/js-question-mark-article텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)